Merge lp:~zematynnad/ubuntu-webcatalog/fix_no_enlarger_845911 into lp:ubuntu-webcatalog

Proposed by Danny Tamez
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: 126
Merged at revision: 130
Proposed branch: lp:~zematynnad/ubuntu-webcatalog/fix_no_enlarger_845911
Merge into: lp:ubuntu-webcatalog
Diff against target: 148 lines (+53/-61)
2 files modified
src/webcatalog/static/js/screenshots.js (+53/-60)
src/webcatalog/templates/webcatalog/screenshot_widget.html (+0/-1)
To merge this branch: bzr merge lp:~zematynnad/ubuntu-webcatalog/fix_no_enlarger_845911
Reviewer Review Type Date Requested Status
Canonical Consumer Applications Hackers Pending
Review via email: mp+107848@code.launchpad.net

Commit message

Fix for javascript errors after ajax returns more screenshots for app.

Description of the change

Overview
========
This branch fixes a condition where the screenshot enlarger was not being displayed when screenshots were obtained via ajax.

Details
========
Because the number of screenshots was critical to much of the logic in the screenshots.js page the ajax portion of it was causing some issues when it changed the number of screenshots. For example the setup_carouse function was only defined if there was originally more than one screenshot. So, when via ajax we now had more screenshots the function to set up the carousel was not defined.
So now what the script does is settle at the outset the number of screenshots (via ajax or not) so that the number change happens before any logic that depends on that number.
I also removed a small line of debug code in the html page.

To Run the Tests
=========
$fab bootstrap test

To View the Different Scenarios in the Browser
===============================================
0 screenshots: http://localhost:8000/cat/applications/gstreamer0.10-fluendo-plugins-wmv/
1 screenshot: http://localhost:8000/cat/applications/ubuntu-user-de-issue-201202/
1 screenshot after ajax: http://localhost:8000/cat/applications/skype/
2 or more screenshots: http://localhost:8000/cat/applications/precise/defcon/

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/static/js/screenshots.js'
2--- src/webcatalog/static/js/screenshots.js 2012-05-18 20:40:15 +0000
3+++ src/webcatalog/static/js/screenshots.js 2012-05-29 18:49:22 +0000
4@@ -1,64 +1,11 @@
5 var setup_screenshots = function(num_screenshots, appName, combo_path, ajax_uri) {
6 YUI({combine: true, comboBase: combo_path, root: 'yui/3.4.0/build/'}).use('io-base','uwc-carousel', function(Y) {
7-
8- Y.on('domready', setupViewerPanel, false);
9- // viewer needs to be setup even if there is only one screenshot and no carousel is used
10- function setupViewerPanel(addedMoreViaAjax) {
11- // don't set up if there are no screenshots
12- if (num_screenshots == 0) {
13- // but do set up if we get called a second time when adding screenshots via ajax
14- if (!addedMoreViaAjax) {
15- return;
16- }
17- }
18- var panel = new Y.Panel({
19- width: 860,
20- centered: true,
21- zIndex: 50,
22- modal: true,
23- visible: false,
24- render: false,
25- buttons: [
26- {
27- value: 'Close',
28- section: 'footer',
29- action: function(e) {
30- e.preventDefault();
31- panel.hide();
32- }
33- }
34- ]
35- });
36- var bb = panel.get('boundingBox');
37- var slides = Y.all('.slide img');
38- slides.on("click", function(e){
39- var slide = e.currentTarget;
40- var url = slide.getAttribute('src');
41- heading = appName + ' - screeshot ';
42- panel.setStdModContent(Y.WidgetStdMod.HEADER, heading);
43- panel.setStdModContent(Y.WidgetStdMod.BODY, '<img width="800" src="' + url +'"/>');
44- panel.render('#viewerPanel');
45- panel.show();
46- }, this);
47- }
48-
49- if (num_screenshots > 1) {
50- function setup_carousel() {
51- var caro = new Y.uwc.Carousel({
52- nodeContainer: "#screenshots-carousel",
53- controlsContainer: "#nocontrols",
54- autoPlay: false,
55- slideAnimDuration: 0.6
56- });
57- Y.all('.slide').removeClass('disabled');
58- }
59- }
60-
61 if (num_screenshots == 0) {
62 var uri = ajax_uri;
63 function complete(id, obj) {
64 var json = JSON.parse(obj.responseText);
65- if (json.length > 1) {
66+ num_screenshots = json.length;
67+ if (num_screenshots > 0) {
68 var content_div = document.createElement('div');
69 content_div.className = 'carousel-wrapper';
70 var carousel_div = document.createElement('div');
71@@ -81,16 +28,62 @@
72 screenshots_div.get('childNodes').remove();
73 screenshots_div.appendChild(content_div);
74 setup_carousel();
75- setupViewerPanel(true);
76- } else if (json.lenth == 1) {
77- // in case we only got back 1 from ajax - still need the viewer
78- setupViewerPanel(true);
79- }
80+ setupViewerPanel();
81+ };
82 };
83 Y.on('io:complete', complete, Y);
84 var request = Y.io(uri);
85 } else {
86 setup_carousel();
87+ setupViewerPanel();
88+ }
89+
90+ function setupViewerPanel() {
91+ if (num_screenshots == 0) {
92+ return;
93+ }
94+ var panel = new Y.Panel({
95+ width: 860,
96+ centered: true,
97+ zIndex: 50,
98+ modal: true,
99+ visible: false,
100+ render: false,
101+ buttons: [
102+ {
103+ value: 'Close',
104+ section: 'footer',
105+ action: function(e) {
106+ e.preventDefault();
107+ panel.hide();
108+ }
109+ }
110+ ]
111+ });
112+ var bb = panel.get('boundingBox');
113+ var slides = Y.all('.slide img');
114+ slides.on("click", function(e){
115+ var slide = e.currentTarget;
116+ var url = slide.getAttribute('src');
117+ heading = appName + ' - screeshot ';
118+ panel.setStdModContent(Y.WidgetStdMod.HEADER, heading);
119+ panel.setStdModContent(Y.WidgetStdMod.BODY, '<img width="800" src="' + url +'"/>');
120+ panel.render('#viewerPanel');
121+ panel.show();
122+ }, this);
123+ }
124+
125+ function setup_carousel() {
126+ if (num_screenshots < 2) {
127+ return;
128+ }
129+ var caro = new Y.uwc.Carousel({
130+ nodeContainer: "#screenshots-carousel",
131+ controlsContainer: "#nocontrols",
132+ autoPlay: false,
133+ slideAnimDuration: 0.6
134+ });
135+ Y.all('.slide').removeClass('disabled');
136 }
137 });
138 }
139
140=== modified file 'src/webcatalog/templates/webcatalog/screenshot_widget.html'
141--- src/webcatalog/templates/webcatalog/screenshot_widget.html 2012-05-08 17:03:43 +0000
142+++ src/webcatalog/templates/webcatalog/screenshot_widget.html 2012-05-29 18:49:22 +0000
143@@ -1,5 +1,4 @@
144 {% load url from future %}
145-<div id='console'></div>
146 <div id="screenshots_placeholder">
147 {% if application.screenshots|length_is:0 %}
148 <img src="http://screenshots.ubuntu.com/thumbnail-with-version/{{ application.package_name }}/ignored" />

Subscribers

People subscribed via source and target branches