Commit 26cd97af6efb4fb7dbe3f92e0639c68e3f17c5db
1 parent
7248c9ba
Exists in
master
and in
29 other branches
[media-panel-improvements] Create folder on demand
Showing
3 changed files
with
39 additions
and
2 deletions
Show diff stats
app/controllers/my_profile/cms_controller.rb
... | ... | @@ -114,7 +114,7 @@ class CmsController < MyProfileController |
114 | 114 | @success_back_to = params[:success_back_to] |
115 | 115 | # user must choose an article type first |
116 | 116 | |
117 | - @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id] | |
117 | + @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id].present? | |
118 | 118 | record_coming |
119 | 119 | @type = params[:type] |
120 | 120 | if @type.blank? |
... | ... | @@ -159,7 +159,10 @@ class CmsController < MyProfileController |
159 | 159 | if continue |
160 | 160 | redirect_to :action => 'edit', :id => @article |
161 | 161 | else |
162 | - success_redirect | |
162 | + respond_to do |format| | |
163 | + format.html { success_redirect } | |
164 | + format.json { render :text => {:id => @article.id, :full_name => profile.identifier + '/' + @article.full_name}.to_json } | |
165 | + end | |
163 | 166 | end |
164 | 167 | return |
165 | 168 | end | ... | ... |
app/views/cms/_text_editor_sidebar.html.erb
... | ... | @@ -15,6 +15,7 @@ |
15 | 15 | :parent_id, profile, default_folder, {}, {}, |
16 | 16 | "type='Folder' or type='Gallery'" |
17 | 17 | ) %> |
18 | + <%= labelled_form_field _('Or create a folder under the selected above:'), text_field_tag(:new_folder, nil, 'data-url' => url_for({:action => 'new', :profile => profile.identifier})) %> | |
18 | 19 | </div> |
19 | 20 | <p><%= file_field_tag('file', :multiple => true) %></p> |
20 | 21 | <% end %> | ... | ... |
public/javascripts/media-panel.js
... | ... | @@ -84,3 +84,36 @@ jQuery("#published-media #q").typeWatch({ |
84 | 84 | }); |
85 | 85 | |
86 | 86 | jQuery("#published-media #q").bind('notext', function(){ loadPublishedMedia() }); |
87 | + | |
88 | +jQuery("#new_folder").keypress(function( event ) { | |
89 | + if ( event.which == 13 ) { | |
90 | + event.preventDefault(); | |
91 | + var url = jQuery(this).data('url'); | |
92 | + var name = jQuery(this).val(); | |
93 | + var parent_id = jQuery("#media-upload-box #parent_id").val(); | |
94 | + jQuery('#media-upload-form').addClass('fetching'); | |
95 | + jQuery.ajax({ | |
96 | + url: url, | |
97 | + type: 'POST', | |
98 | + data: { | |
99 | + 'parent_id': parent_id, | |
100 | + 'article': {'name': name, 'published': true}, | |
101 | + 'type': 'Folder' }, | |
102 | + dataType: 'json', | |
103 | + success: function(response) { | |
104 | + var option_selected = "<option value='"+ response.id +"' selected='selected'>"+ response.full_name +"</options>" | |
105 | + var option = "<option value='"+ response.id +"'>"+ response.full_name +"</options>" | |
106 | + jQuery('#media-upload-form #parent_id').append(option_selected); | |
107 | + jQuery('#published-media #parent_id').append(option); | |
108 | + jQuery('#new_folder').val(''); | |
109 | + }, | |
110 | + error: function(response, textStatus, xhr) { | |
111 | + console.log(response); | |
112 | + console.log(textStatus); | |
113 | + }, | |
114 | + complete: function(response){ | |
115 | + jQuery('#media-upload-form').removeClass('fetching'); | |
116 | + } | |
117 | + }); | |
118 | + } | |
119 | +}) | ... | ... |