Commit 29f9c09439e017356f717255c104895a646bcf54
1 parent
0c3de4a1
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
dspace_plugin : refactoring add action for communities & collections
Showing
13 changed files
with
256 additions
and
13 deletions
Show diff stats
plugins/dspace/controllers/dspace_plugin_controller.rb
... | ... | @@ -2,8 +2,24 @@ class DspacePluginController < PublicController |
2 | 2 | append_view_path File.join(File.dirname(__FILE__) + '/../views') |
3 | 3 | |
4 | 4 | def view_item |
5 | - @collection = DspacePlugin::Collection.find(params[:collection_id]) | |
6 | - @item = Dspace::Item.get_item_by_id 6 | |
5 | + | |
6 | + collection_id = params[:collection_id] | |
7 | + item_id = params[:id] | |
8 | + | |
9 | + begin | |
10 | + @item = Dspace::Item.get_item_by_id item_id | |
11 | + rescue ActiveResource::UnauthorizedAccess | |
12 | + render_not_found | |
13 | + return | |
14 | + end | |
15 | + | |
16 | + begin | |
17 | + @collection = DspacePlugin::Collection.find(collection_id) | |
18 | + rescue ActiveRecord::RecordNotFound | |
19 | + render_not_found | |
20 | + return | |
21 | + end | |
22 | + | |
7 | 23 | end |
8 | 24 | |
9 | 25 | end | ... | ... |
plugins/dspace/controllers/dspace_plugin_myprofile_controller.rb
0 → 100644
... | ... | @@ -0,0 +1,79 @@ |
1 | +class DspacePluginMyprofileController < CmsController | |
2 | + append_view_path File.join(File.dirname(__FILE__) + '/../views') | |
3 | + | |
4 | + def new_dspace_content | |
5 | + | |
6 | + @success_back_to = params[:success_back_to] | |
7 | + | |
8 | + @parent = profile.articles.find(params[:parent_id]) if params && params[:parent_id] | |
9 | + record_coming | |
10 | + @type = params[:type] | |
11 | + if @type.blank? | |
12 | + @article_types = [] | |
13 | + available_article_types.each do |type| | |
14 | + @article_types.push({ | |
15 | + :class => type, | |
16 | + :short_description => type.short_description, | |
17 | + :description => type.description | |
18 | + }) | |
19 | + end | |
20 | + @parent_id = params[:parent_id] | |
21 | + render :action => 'select_article_type', :layout => false, :back_to => @back_to | |
22 | + return | |
23 | + else | |
24 | + refuse_blocks | |
25 | + end | |
26 | + | |
27 | + raise "Invalid article type #{@type}" unless valid_article_type?(@type) | |
28 | + | |
29 | + klass = @type.constantize | |
30 | + article_data = environment.enabled?('articles_dont_accept_comments_by_default') ? { :accept_comments => false } : {} | |
31 | + article_data.merge!(params[:article]) if params[:article] | |
32 | + | |
33 | + if @type == 'DspacePlugin::Collection' | |
34 | + ids_list = 'dspace_collections_ids' | |
35 | + names_list = 'dspace_collections_names' | |
36 | + elsif @type == 'DspacePlugin::Communityy' | |
37 | + ids_list = 'dspace_communities_ids' | |
38 | + names_list = 'dspace_communities_names' | |
39 | + end | |
40 | + | |
41 | + index = -1 | |
42 | + | |
43 | + article_data[ids_list].each do |id| | |
44 | + | |
45 | + index += 1 | |
46 | + | |
47 | + name = article_data[names_list][index] | |
48 | + | |
49 | + entity = klass.new | |
50 | + | |
51 | + parent = check_parent(params[:parent_id]) | |
52 | + | |
53 | + if parent | |
54 | + entity.parent = parent | |
55 | + parent_id = parent.id | |
56 | + end | |
57 | + | |
58 | + entity.dspace_community_id = id if @type == 'DspacePlugin::Communityy' | |
59 | + | |
60 | + if @type == 'DspacePlugin::Collection' | |
61 | + entity.dspace_collection_id = id | |
62 | + entity.dspace_community_id = article_data['dspace_community_id'] | |
63 | + end | |
64 | + | |
65 | + entity.profile = profile | |
66 | + entity.author = user | |
67 | + entity.last_changed_by = user | |
68 | + entity.created_by = user | |
69 | + entity.name = name | |
70 | + | |
71 | + entity.save! | |
72 | + | |
73 | + end | |
74 | + | |
75 | + redirect_to @parent.view_url | |
76 | + | |
77 | + end | |
78 | + | |
79 | +end | ... | ... |
plugins/dspace/lib/dspace/item.rb
... | ... | @@ -0,0 +1,22 @@ |
1 | +function selectCommunity(element, community_slug) { | |
2 | + var hidden_field = jQuery('<input>').attr({ | |
3 | + id: 'article_dspace_community_name_', | |
4 | + name: 'article[dspace_communities_names][]', | |
5 | + type: 'hidden', | |
6 | + name: 'article[dspace_communities_names][]', | |
7 | + value: community_slug | |
8 | + }); | |
9 | + jQuery(hidden_field).insertAfter(element); | |
10 | +} | |
11 | + | |
12 | +function selectCollection(element, collection_slug) { | |
13 | + var hidden_field = jQuery('<input>').attr({ | |
14 | + id: 'article_dspace_collection_name_', | |
15 | + name: 'article[dspace_collections_names][]', | |
16 | + type: 'hidden', | |
17 | + name: 'article[dspace_collections_names][]', | |
18 | + value: collection_slug | |
19 | + }); | |
20 | + jQuery(hidden_field).insertAfter(element); | |
21 | +} | |
22 | + | ... | ... |
plugins/dspace/public/style.css
plugins/dspace/views/cms/dspace_plugin/_collection.html.erb
1 | 1 | <h1><%= _('DSpace Collection') %></h1> |
2 | 2 | |
3 | -<%= required_fields_message %> | |
3 | +<%#= required_fields_message %> | |
4 | 4 | |
5 | -<%= required f.text_field('name', :size => '64', :maxlength => 150) %> | |
5 | +<%#= required f.text_field('name', :size => '64', :maxlength => 150) %> | |
6 | 6 | |
7 | 7 | <%= hidden_field_tag 'article[parent_id]', @article.parent_id %> |
8 | 8 | |
... | ... | @@ -16,7 +16,23 @@ |
16 | 16 | |
17 | 17 | <% collections = Dspace::Community.get_all_collections_from( dspace_server_url, community_id ).map { |collection| item = [_(collection.name), collection.id] } %> |
18 | 18 | |
19 | -<%= labelled_form_field(_('Collections:'), | |
19 | +<table border="0"> | |
20 | + <tr> | |
21 | + <th><%= check_box_tag "article[dspace_collection_id]", true %></th> | |
22 | + <th align="left"><%= _('DSpace Collection') %></th> | |
23 | + </tr> | |
24 | + <% collections.each do |collection| %> | |
25 | + <tr> | |
26 | + <td align="center"><%= check_box_tag "article[dspace_collection_id][]", collection[1] %> </td> | |
27 | + <td> | |
28 | + <%= hidden_field_tag "article[dspace_collection_name][]", collection[0].to_slug %> | |
29 | + <%= collection[0] %> | |
30 | + </td> | |
31 | + </tr> | |
32 | + <% end %> | |
33 | +</table> | |
34 | + | |
35 | +<%#= labelled_form_field(_('Collections:'), | |
20 | 36 | select(:article, |
21 | 37 | :dspace_collection_id, |
22 | 38 | options_for_select_with_title(collections))) %> | ... | ... |
plugins/dspace/views/cms/dspace_plugin/_item.html.erb
plugins/dspace/views/content_viewer/_item.html.erb
1 | 1 | <li class="item"> |
2 | - <!--span class="name"><%#= item.name %></span><br /--> | |
3 | 2 | <span class="name"><%= link_to item.name, :controller => 'dspace_plugin', :action => 'view_item', :id => item.id, :collection_id => @page.id %></span><br /> |
4 | 3 | <span class="authors"><%= item.author %></span> <span class="date_issued">(<%= item.issue_date %>)</span> |
5 | 4 | </li> | ... | ... |
plugins/dspace/views/content_viewer/community.html.erb
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | <% if dspace_community.allow_create?(user) %> |
7 | 7 | |
8 | 8 | <div id="actions"> |
9 | - <%= content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "DspacePlugin::Collection", :parent_id => dspace_community.id}), :class => 'button with-text icon-add') do %> | |
9 | + <%= content_tag('a', :href => url_for({:controller => 'dspace_plugin_myprofile', :action => 'new', :type => "DspacePlugin::Collection", :parent_id => dspace_community.id}), :class => 'button with-text icon-add') do %> | |
10 | 10 | <%= _("Add a %s") % DspacePlugin::Collection.short_description %> |
11 | 11 | <% end %> |
12 | 12 | </div> |
... | ... | @@ -22,4 +22,3 @@ |
22 | 22 | </div> |
23 | 23 | |
24 | 24 | </div> |
25 | - | ... | ... |
plugins/dspace/views/content_viewer/library.html.erb
... | ... | @@ -3,7 +3,7 @@ |
3 | 3 | <% if dspace_library.allow_create?(user) %> |
4 | 4 | |
5 | 5 | <div id="actions"> |
6 | - <%= content_tag('a', :href => url_for({:controller => 'cms', :action => 'new', :type => "DspacePlugin::Communityy", :parent_id => dspace_library.id}), :class => 'button with-text icon-add') do %> | |
6 | + <%= content_tag('a', :href => url_for({:controller => 'dspace_plugin_myprofile', :action => 'new', :type => "DspacePlugin::Communityy", :parent_id => dspace_library.id}), :class => 'button with-text icon-add') do %> | |
7 | 7 | <%= _("Add a %s") % DspacePlugin::Communityy.short_description %> |
8 | 8 | <% end %> |
9 | 9 | </div> | ... | ... |
plugins/dspace/views/dspace_plugin_myprofile/dspace_plugin/_collection.html.erb
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +<h1><%= _('DSpace Collections') %></h1> | |
2 | + | |
3 | +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %> | |
4 | + | |
5 | +<%= hidden_field_tag 'article[dspace_community_id]', @article.parent.dspace_community_id %> | |
6 | + | |
7 | +<% dspace_server_url = @article.parent.parent.dspace_server_url %> | |
8 | + | |
9 | +<% community_id = @article.parent.dspace_community_id %> | |
10 | + | |
11 | +<% collections = Dspace::Community.get_all_collections_from( dspace_server_url, community_id ).map { |collection| item = [_(collection.name), collection.id] } %> | |
12 | + | |
13 | +<table border="0" style="border-bottom: 1px solid #c0c0c0;"> | |
14 | + <tr style="background-color: #f0f0f0; border-bottom: 1px solid #c0c0c0;"> | |
15 | + <th style="border-bottom: none;"> </th> | |
16 | + <th style="border-bottom: none;" align="left"><%= _('Collection name') %></th> | |
17 | + </tr> | |
18 | + | |
19 | + <% dspace_collections_ids = DspacePlugin::Collection.find(:all, :conditions => { :parent_id => @article.parent_id}).map { |collection| ids = collection.dspace_collection_id.to_i } %> | |
20 | + | |
21 | + <% collections.each do |collection| %> | |
22 | + | |
23 | + <tr> | |
24 | + <% if dspace_collections_ids.include? collection[1] %> | |
25 | + <td align="center"><%= check_box_tag "article[dspace_collections_ids][]", collection[1], true, :disabled => 'disabled', :onclick => "selectCollection(this,'#{collection[0]}')" %> </td> | |
26 | + <% else %> | |
27 | + <td align="center"><%= check_box_tag "article[dspace_collections_ids][]", collection[1], false, :onclick => "selectCollection(this,'#{collection[0]}')" %> </td> | |
28 | + <% end %> | |
29 | + <td> | |
30 | + <%= collection[0] %> | |
31 | + </td> | |
32 | + </tr> | |
33 | + | |
34 | + <% end %> | |
35 | + | |
36 | +</table> | |
37 | + | |
38 | +<%= javascript_include_tag 'plugins/dspace/javascripts/dspace_plugin' %> | ... | ... |
plugins/dspace/views/dspace_plugin_myprofile/dspace_plugin/_communityy.html.erb
0 → 100644
... | ... | @@ -0,0 +1,34 @@ |
1 | +<h1><%= _('DSpace Communities') %></h1> | |
2 | + | |
3 | +<%= hidden_field_tag 'article[parent_id]', @article.parent_id %> | |
4 | + | |
5 | +<% dspace_server_url = @article.parent.dspace_server_url %> | |
6 | + | |
7 | +<% communities = Dspace::Community.get_all_communities_from(dspace_server_url).map { |community| item = [_(community.name), community.id] } %> | |
8 | + | |
9 | +<table border="0" style="border-bottom: 1px solid #c0c0c0;"> | |
10 | + <tr style="background-color: #f0f0f0; border-bottom: 1px solid #c0c0c0;"> | |
11 | + <th style="border-bottom: none;"> </th> | |
12 | + <th style="border-bottom: none;" align="left"><%= _('Community name') %></th> | |
13 | + </tr> | |
14 | + | |
15 | + <% dspace_communities_ids = DspacePlugin::Communityy.find(:all, :conditions => { :parent_id => @article.parent_id }).map { |community| ids = community.dspace_community_id.to_i } %> | |
16 | + | |
17 | + <% communities.each do |community| %> | |
18 | + | |
19 | + <tr> | |
20 | + <% if dspace_communities_ids.include? community[1] %> | |
21 | + <td align="center"><%= check_box_tag "article[dspace_communities_ids][]", community[1], true, :disabled => 'disabled', :onclick => "selectCommunity(this,'#{community[0]}')" %> </td> | |
22 | + <% else %> | |
23 | + <td align="center"><%= check_box_tag "article[dspace_communities_ids][]", community[1], false, :onclick => "selectCommunity(this,'#{community[0]}')" %> </td> | |
24 | + <% end %> | |
25 | + <td> | |
26 | + <%= community[0] %> | |
27 | + </td> | |
28 | + </tr> | |
29 | + | |
30 | + <% end %> | |
31 | + | |
32 | +</table> | |
33 | + | |
34 | +<%= javascript_include_tag 'plugins/dspace/javascripts/dspace_plugin' %> | ... | ... |
plugins/dspace/views/dspace_plugin_myprofile/edit.html.erb
0 → 100644
... | ... | @@ -0,0 +1,42 @@ |
1 | +<%= error_messages_for 'article' %> | |
2 | + | |
3 | +<div class='<%= (environment.enabled?('media_panel') ? 'with_media_panel' : 'no_media_panel') %>'> | |
4 | + | |
5 | +<%= labelled_form_for 'article', :url => {action: "new_dspace_content"}, :html => { :multipart => true, :class => @type } do |f| %> | |
6 | + | |
7 | + <%= hidden_field_tag("type", @type) if @type %> | |
8 | + | |
9 | + <%= hidden_field_tag('parent_id', @parent_id) if @parent_id %> | |
10 | + | |
11 | + <%= hidden_field_tag('back_to', @back_to) %> | |
12 | + | |
13 | + <%= hidden_field_tag('success_back_to', @success_back_to) %> | |
14 | + | |
15 | + <%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %> | |
16 | + | |
17 | + <% button_bar do %> | |
18 | + <%= submit_button :save, _('Save') %> | |
19 | + | |
20 | + <% if @back_to %> | |
21 | + <%= button :cancel, _('Cancel'), @back_to %> | |
22 | + <% elsif @parent_id || @article.parent %> | |
23 | + <%= button :cancel, _('Cancel'), :action => 'view', :id => @parent_id || @article.parent %> | |
24 | + <% else %> | |
25 | + <%= button :cancel, _('Cancel'), :action => 'index' %> | |
26 | + <% end %> | |
27 | + | |
28 | + <% unless @article.new_record? %> | |
29 | + <%= button :delete, _('Delete'), {:controller => :cms, :action => :destroy, :id => @article}, | |
30 | + :method => :post, :confirm => delete_article_message(@article) %> | |
31 | + <% end %> | |
32 | + <% end %> | |
33 | +<% end %> | |
34 | +</div> | |
35 | + | |
36 | +<% if environment.enabled?('media_panel') && [TinyMceArticle, TextileArticle, Event, EnterpriseHomepage].any?{|klass| @article.kind_of?(klass)} %> | |
37 | + <%= render :partial => 'text_editor_sidebar' %> | |
38 | +<% end %> | |
39 | + | |
40 | +<br style='clear: both'/> | |
41 | + | |
42 | +<%= javascript_include_tag "article.js" %> | ... | ... |