Commit 57ac92afa5356e6de131a6c2f100d8945dc069d5
Committed by
Rodrigo Souto
1 parent
8a4841d6
Exists in
master
and in
22 other branches
Fix tests
- The loading bar was fixed to fix media_panel_upload broken tests - The noosfero_steps was fixed to get the first box(this was breaking when it was on the environment. Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Showing
2 changed files
with
159 additions
and
132 deletions
Show diff stats
features/step_definitions/noosfero_steps.rb
... | ... | @@ -94,7 +94,7 @@ Given /^the following blocks$/ do |table| |
94 | 94 | owner.boxes<< Box.new |
95 | 95 | owner.boxes.first.blocks << MainBlock.new |
96 | 96 | end |
97 | - box = owner.boxes.where(:position => 3).first | |
97 | + box = owner.boxes.first | |
98 | 98 | klass.constantize.create!(item.merge(:box => box)) |
99 | 99 | end |
100 | 100 | end | ... | ... |
public/javascripts/media-panel.js
1 | -var file_id = 1; | |
2 | - | |
3 | -jQuery('.view-all-media').on('click', '.pagination a', function(event) { | |
4 | - jQuery.ajax({ | |
5 | - url: this.href, | |
6 | - beforeSend: function(){jQuery('.view-all-media').addClass('fetching')}, | |
7 | - complete: function() {jQuery('.view-all-media').removeClass('fetching')}, | |
8 | - dataType: 'script' | |
1 | +(function($) { | |
2 | + "use strict"; | |
3 | + | |
4 | + var file_id = 1; | |
5 | + | |
6 | + $('.view-all-media').on('click', '.pagination a', function(event) { | |
7 | + $.ajax({ | |
8 | + url: this.href, | |
9 | + beforeSend: function(){$('.view-all-media').addClass('fetching')}, | |
10 | + complete: function() {$('.view-all-media').removeClass('fetching')}, | |
11 | + dataType: 'script' | |
12 | + }); | |
13 | + return false; | |
9 | 14 | }); |
10 | - return false; | |
11 | -}); | |
12 | - | |
13 | -jQuery('#file').fileupload({ | |
14 | - add: function(e, data){ | |
15 | - data.files[0].id = file_id; | |
16 | - file_id++; | |
17 | - data.context = jQuery(tmpl("template-upload", data.files[0])); | |
18 | - jQuery('#media-upload-form').append(data.context); | |
19 | - data.submit(); | |
20 | - }, | |
21 | - progress: function (e, data) { | |
22 | - if (jQuery('#hide-uploads').data('bootstraped') == false) { | |
23 | - jQuery('#hide-uploads').show(); | |
24 | - jQuery('#hide-uploads').data('bootstraped', true); | |
25 | - } | |
26 | - if (data.context) { | |
27 | - progress = parseInt(data.loaded / data.total * 100, 10); | |
28 | - data.context.find('.bar').css('width', progress + '%'); | |
29 | - data.context.find('.percentage').text(progress + '%'); | |
30 | - } | |
31 | - }, | |
32 | - fail: function(e, data){ | |
33 | - var file_id = '#file-'+data.files[0].id; | |
34 | - jQuery(file_id).find('.progress .bar').addClass('error'); | |
35 | - jQuery(file_id).append("<div class='error-message'>" + data.jqXHR.responseText + "</div>") | |
36 | - } | |
37 | -}); | |
38 | - | |
39 | -jQuery('#hide-uploads').click(function(){ | |
40 | - jQuery('#hide-uploads').hide(); | |
41 | - jQuery('#show-uploads').show(); | |
42 | - jQuery('.upload').slideUp(); | |
43 | - return false; | |
44 | -}); | |
45 | - | |
46 | -jQuery('#show-uploads').click(function(){ | |
47 | - jQuery('#hide-uploads').show(); | |
48 | - jQuery('#show-uploads').hide(); | |
49 | - jQuery('.upload').slideDown(); | |
50 | - return false; | |
51 | -}); | |
52 | - | |
53 | -function loadPublishedMedia() { | |
54 | - var parent_id = jQuery('#published-media #parent_id').val(); | |
55 | - var q = jQuery('#published-media #q').val(); | |
56 | - var url = jQuery('#published-media').data('url'); | |
57 | - | |
58 | - jQuery('#published-media .items').addClass('fetching'); | |
59 | - jQuery.ajax({ | |
60 | - url: url, | |
61 | - data: {'parent_id': parent_id, 'q': q}, | |
62 | - dataType: 'html', | |
63 | - success: function(response) { | |
64 | - jQuery("#published-media .items").html(response); | |
65 | - jQuery('#published-media .items').removeClass('fetching'); | |
66 | - updateViewAllLinks(); | |
15 | + | |
16 | + | |
17 | + $('#file').fileupload({ | |
18 | + add: function(e, data){ | |
19 | + data.files[0].id = file_id; | |
20 | + file_id++; | |
21 | + data.context = $(tmpl("template-upload", data.files[0])); | |
22 | + $('#media-upload-form').append(data.context); | |
23 | + data.submit(); | |
24 | + }, | |
25 | + progress: function (e, data) { | |
26 | + if ($('#hide-uploads').data('bootstraped') == false) { | |
27 | + $('#hide-uploads').show(); | |
28 | + $('#hide-uploads').data('bootstraped', true); | |
29 | + } | |
30 | + if (data.context) { | |
31 | + var progress = parseInt(data.loaded / data.total * 100, 10); | |
32 | + data.context.find('.bar').css('width', progress + '%'); | |
33 | + data.context.find('.percentage').text(progress + '%'); | |
34 | + } | |
67 | 35 | }, |
68 | - error: function(response, textStatus, xhr) { | |
69 | - console.log(response); | |
70 | - console.log(textStatus); | |
36 | + fail: function(e, data){ | |
37 | + var file_id = '#file-'+data.files[0].id; | |
38 | + $(file_id).find('.progress .bar').addClass('error'); | |
39 | + $(file_id).append("<div class='error-message'>" + data.jqXHR.responseText + "</div>") | |
71 | 40 | } |
72 | 41 | }); |
73 | -} | |
74 | - | |
75 | -function updateViewAllLinks() { | |
76 | - var parent_id = jQuery('#published-media #parent_id').val(); | |
77 | - var q = jQuery('#published-media #q').val(); | |
78 | - jQuery('#published-media .view-all').each(function(){ | |
79 | - var key = jQuery(this).data('key'); | |
80 | - var params = {parent_id: parent_id, q: q, key: key} | |
81 | - var href = jQuery(this).attr('href'); | |
82 | - href = href.replace(/\?.*/, '?'+jQuery.param(params)); | |
83 | - jQuery(this).attr('href', href); | |
42 | + | |
43 | + | |
44 | + $('#hide-uploads').click(function(){ | |
45 | + $('#hide-uploads').hide(); | |
46 | + $('#show-uploads').show(); | |
47 | + $('.upload').slideUp(); | |
48 | + return false; | |
49 | + }); | |
50 | + | |
51 | + | |
52 | + $('#show-uploads').click(function(){ | |
53 | + $('#hide-uploads').show(); | |
54 | + $('#show-uploads').hide(); | |
55 | + $('.upload').slideDown(); | |
56 | + return false; | |
84 | 57 | }); |
85 | -} | |
86 | - | |
87 | -jQuery('#published-media #parent_id').change(function(){ loadPublishedMedia() }); | |
88 | - | |
89 | -jQuery("#published-media #q").typeWatch({ | |
90 | - callback: function (value) { loadPublishedMedia() }, | |
91 | - wait: 750, | |
92 | - highlight: true, | |
93 | - captureLength: 2 | |
94 | -}); | |
95 | - | |
96 | -jQuery("#published-media #q").bind('notext', function(){ loadPublishedMedia() }); | |
97 | - | |
98 | -jQuery("#new-folder-dialog").submit(function( event ) { | |
99 | - var name = jQuery('#new_folder').val(); | |
100 | - var parent_id = jQuery("#new-folder-dialog #parent_id").val(); | |
101 | - jQuery.ajax({ | |
102 | - url: this.action, | |
103 | - type: 'POST', | |
104 | - data: { | |
105 | - 'parent_id': parent_id, | |
106 | - 'article': {'name': name, 'published': true}, | |
107 | - 'type': jQuery('input[name=folder_type]:checked').val() }, | |
108 | - dataType: 'json', | |
109 | - beforeSend: function(){jQuery("#new-folder-dialog").addClass('fetching')}, | |
110 | - success: function(response) { | |
111 | - var option_selected = "<option value='"+ response.id +"' selected='selected'>"+ response.full_name +"</options>" | |
112 | - var option = "<option value='"+ response.id +"'>"+ response.full_name +"</options>" | |
113 | - jQuery('#media-upload-form #parent_id').append(option_selected); | |
114 | - jQuery('#published-media #parent_id').append(option); | |
115 | - jQuery('#new_folder').val(''); | |
116 | - }, | |
117 | - error: function(response, textStatus, xhr) { | |
118 | - console.log(response); | |
119 | - console.log(textStatus); | |
120 | - }, | |
121 | - complete: function(response){ | |
122 | - jQuery("#new-folder-dialog").removeClass('fetching'); | |
123 | - jQuery("#new-folder-dialog").dialog('close'); | |
124 | - } | |
58 | + | |
59 | + | |
60 | + function loadPublishedMedia() { | |
61 | + var parent_id = $('#published-media #parent_id').val(); | |
62 | + var q = $('#published-media #q').val(); | |
63 | + var url = $('#published-media').data('url'); | |
64 | + | |
65 | + $('#published-media .items').addClass('fetching'); | |
66 | + $.ajax({ | |
67 | + url: url, | |
68 | + data: {'parent_id': parent_id, 'q': q}, | |
69 | + dataType: 'html', | |
70 | + success: function(response) { | |
71 | + $("#published-media .items").html(response); | |
72 | + $('#published-media .items').removeClass('fetching'); | |
73 | + updateViewAllLinks(); | |
74 | + }, | |
75 | + error: function(response, textStatus, xhr) { | |
76 | + console.log(response); | |
77 | + console.log(textStatus); | |
78 | + } | |
79 | + }); | |
80 | + } | |
81 | + // make it global for usage in media_upload.js.erb | |
82 | + window.loadPublishedMedia = loadPublishedMedia; | |
83 | + | |
84 | + | |
85 | + function updateViewAllLinks() { | |
86 | + var parent_id = $('#published-media #parent_id').val(); | |
87 | + var q = $('#published-media #q').val(); | |
88 | + $('#published-media .view-all').each(function(){ | |
89 | + var key = $(this).data('key'); | |
90 | + var params = {parent_id: parent_id, q: q, key: key} | |
91 | + var href = $(this).attr('href'); | |
92 | + href = href.replace(/\?.*/, '?'+$.param(params)); | |
93 | + $(this).attr('href', href); | |
94 | + }); | |
95 | + } | |
96 | + | |
97 | + | |
98 | + $('#published-media #parent_id').change(function(){ | |
99 | + loadPublishedMedia() | |
100 | + }); | |
101 | + | |
102 | + | |
103 | + // Using a immediate function to make timer variable only visible for the keyup event | |
104 | + (function() { | |
105 | + var timer = null; | |
106 | + | |
107 | + $("#published-media #q").keyup(function() { | |
108 | + if(this.value.length > 2) { | |
109 | + timer = setTimeout(loadPublishedMedia, 750); | |
110 | + } | |
111 | + }).keydown(function() { | |
112 | + clearTimeout(timer); | |
113 | + }); | |
114 | + }) (); | |
115 | + | |
116 | + | |
117 | + $("#published-media #q").bind('notext', function(){ | |
118 | + loadPublishedMedia() | |
119 | + }); | |
120 | + | |
121 | + | |
122 | + $("#new-folder-dialog").submit(function( event ) { | |
123 | + var name = $('#new_folder').val(); | |
124 | + var parent_id = $("#new-folder-dialog #parent_id").val(); | |
125 | + $.ajax({ | |
126 | + url: this.action, | |
127 | + type: 'POST', | |
128 | + data: { | |
129 | + 'parent_id': parent_id, | |
130 | + 'article': {'name': name, 'published': true}, | |
131 | + 'type': $('input[name=folder_type]:checked').val() }, | |
132 | + dataType: 'json', | |
133 | + beforeSend: function(){$("#new-folder-dialog").addClass('fetching')}, | |
134 | + success: function(response) { | |
135 | + var option_selected = "<option value='"+ response.id +"' selected='selected'>"+ response.full_name +"</options>" | |
136 | + var option = "<option value='"+ response.id +"'>"+ response.full_name +"</options>" | |
137 | + $('#media-upload-form #parent_id').append(option_selected); | |
138 | + $('#published-media #parent_id').append(option); | |
139 | + $('#new_folder').val(''); | |
140 | + }, | |
141 | + error: function(response, textStatus, xhr) { | |
142 | + console.log(response); | |
143 | + console.log(textStatus); | |
144 | + }, | |
145 | + complete: function(response){ | |
146 | + $("#new-folder-dialog").removeClass('fetching'); | |
147 | + $("#new-folder-dialog").dialog('close'); | |
148 | + } | |
149 | + }); | |
150 | + return false; | |
151 | + }); | |
152 | + | |
153 | + $('.icon-vertical-toggle').click(function(){ | |
154 | + $('#content').toggleClass('show-media-panel'); | |
155 | + return false; | |
125 | 156 | }); |
126 | - return false; | |
127 | -}); | |
128 | - | |
129 | -jQuery('.text-editor-sidebar .header .icon-vertical-toggle').click(function(){ | |
130 | - jQuery('#content').toggleClass('show-media-panel'); | |
131 | - return false; | |
132 | -}); | |
133 | - | |
134 | -jQuery('#new-folder-button').click(function(){ | |
135 | - jQuery('#new-folder-dialog').dialog({modal: true}); | |
136 | - return false; | |
137 | -}); | |
157 | + | |
158 | + | |
159 | + $('#new-folder-button').click(function(){ | |
160 | + $('#new-folder-dialog').dialog({modal: true}); | |
161 | + return false; | |
162 | + }); | |
163 | + | |
164 | +}) (jQuery); | ... | ... |