From 170c26392763318f2be3e2536828bc89876e01f7 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Wed, 15 Apr 2015 14:43:07 +0200 Subject: [PATCH 01/11] remove uncessary code --- app/controllers/my_projects_overviews_controller.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index bfe80e8d6a..97fde3418a 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -37,7 +37,6 @@ class MyProjectsOverviewsController < ApplicationController end def index - render end # User's page layout configuration From 78edeaec3706781f8b43b5c61f9a8715ef066b9d Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Mon, 20 Apr 2015 16:03:58 +0200 Subject: [PATCH 02/11] repair css - use foundation classes instead This attempts to use the foundation classes to achieve the initial side-by-side layout that got lost after the upgrade --- .../my_project_page/my_projects_overview.css | 26 -------- .../my_project_page/my_projects_overview.sass | 33 ++++++++++ app/helpers/my_projects_overviews_helper.rb | 31 ++++++++++ .../page_layout.html.erb | 60 +++++++++++-------- 4 files changed, 98 insertions(+), 52 deletions(-) delete mode 100644 app/assets/stylesheets/my_project_page/my_projects_overview.css create mode 100644 app/assets/stylesheets/my_project_page/my_projects_overview.sass diff --git a/app/assets/stylesheets/my_project_page/my_projects_overview.css b/app/assets/stylesheets/my_project_page/my_projects_overview.css deleted file mode 100644 index 24154feb2d..0000000000 --- a/app/assets/stylesheets/my_project_page/my_projects_overview.css +++ /dev/null @@ -1,26 +0,0 @@ -/*-- copyright -OpenProject My Project Page Plugin - -Copyright (C) 2011-2014 the OpenProject Foundation (OPF) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License version 3. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - -See doc/COPYRIGHT.md for more details. - -++*/ - -div.overview { - padding:6px; - margin-bottom: 10px; - line-height:1.5em; -} diff --git a/app/assets/stylesheets/my_project_page/my_projects_overview.sass b/app/assets/stylesheets/my_project_page/my_projects_overview.sass new file mode 100644 index 0000000000..7981fe6cea --- /dev/null +++ b/app/assets/stylesheets/my_project_page/my_projects_overview.sass @@ -0,0 +1,33 @@ +// -- copyright +// OpenProject My Project Page Plugin +// +// Copyright (C) 2011-2015 the OpenProject Foundation (OPF) +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License version 3. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +// See doc/COPYRIGHT.md for more details. +@import foundation + +div.overview + padding: 6px + margin-bottom: 10px + line-height: 1.5em + +#visible-grid + .block-receiver + @extend .grid-content + min-height: 32px + // TODO: this fixes an issue which currently breaks the layout + // It has to be removed once it is fixed upstream + &.left, &.right + @extend .medium-6 diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 9207cec17f..55967b6366 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -20,4 +20,35 @@ module MyProjectsOverviewsHelper include WorkPackagesFilterHelper + + TOP = %w(top) + MIDDLE = %w(left right) + BOTTOM = %w(hidden) + + def field_list + TOP + MIDDLE + BOTTOM + end + + def visible_fields + TOP + MIDDLE + end + + def method_missing(name) + constant_name = name.to_s.gsub('_fields', '').upcase + if MyProjectsOverviewsHelper.const_defined? constant_name + return MyProjectsOverviewsHelper.const_get constant_name + end + raise NoMethodError + end + + def sortable_box(field) + sortable_element "list-#{field}", + tag: 'div', + only: 'mypage-box', + handle: 'handle', + dropOnEmpty: true, + containment: field_list.collect { |x| "list-#{x}" }, + constraint: false, + url: { action: 'order_blocks', group: field } + end end diff --git a/app/views/my_projects_overviews/page_layout.html.erb b/app/views/my_projects_overviews/page_layout.html.erb index bf0abcad9c..1c0fb39853 100644 --- a/app/views/my_projects_overviews/page_layout.html.erb +++ b/app/views/my_projects_overviews/page_layout.html.erb @@ -19,9 +19,6 @@ See doc/COPYRIGHT.md for more details. ++#%> - -<% field_list = ['top', 'left', 'right', 'hidden'] %> - -<% content_for :action_menu_specific do %> +<% content_for :toolbar do %>
  • - <%= form_tag({:action => "add_block"}, :id => "block-form") do %> - <%= select_tag 'block', + <%= styled_form_tag({:action => "add_block"}, :id => "block-form") do %> + <%= styled_select_tag 'block', ("" + options_for_select(block_options)).html_safe, :id => "block-select", :onChange => "addBlock();", - class: 'form--select -small' + class: 'form--select' %> <% end %>
  • -
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'icon icon-cancel' %>
  • +
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %>
  • <% end %>

    <%=l(:label_overview)%>

    -<%= render :partial => 'layouts/action_menu_specific' %> +<%= render :partial => 'layouts/toolbar' %>

    <%=l(:label_visible_elements) %>

    <% top_fields.each do |f| %> -
    - <% blocks[f].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => { :block_name => b }) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> - <% end %> -
    + <%= grid_field f %> <% end %>
    <% middle_fields.each do |f| %> -
    - <% blocks[f].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => { :block_name => b }) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> - <% end %> -
    + <%= grid_field f %> <% end %>

    <%=l(:label_hidden_elements) %>

    -
    - <% blocks['hidden'].each do |b| %> - <% if MyProjectsOverviewsController.available_blocks.keys.include? b %> - <%= render(:partial => 'block', :locals => {:block_name => b}) %> - <% elsif b.respond_to? :to_ary %> - <%= render(:partial => 'block_textilizable', - :locals => {:block_name => b.first, - :block_title => b[1], - :textile => b.last}) %> - <% end %> +
    + <% hidden_fields.each do |f| %> + <%= grid_field f %> <% end %>
    From 9daff95440004f6b619e585333ee33d8aca4343d Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Mon, 20 Apr 2015 16:40:38 +0200 Subject: [PATCH 04/11] refactor the weird parts --- app/helpers/my_projects_overviews_helper.rb | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 893ddc86a1..9bd3bb7df7 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -42,14 +42,9 @@ module MyProjectsOverviewsHelper end def grid_field(name) - content_tag :div, id: "list-#{name}", class: %w(block-receiver) + [name] do - ActiveSupport::SafeBuffer.new(blocks[name].map do |block| - if block_available? block - render partial: 'block', locals: { block_name: block } - elsif block.respond_to? :to_ary - render partial: 'block_textilizable', locals: { block_name: block } - end - end.join) + css_classes = %w(block-receiver) + [name] + content_tag :div, id: "list-#{name}", class: css_classes do + ActiveSupport::SafeBuffer.new(blocks[name].map { |b| construct b }.join) end end @@ -64,8 +59,17 @@ module MyProjectsOverviewsHelper url: { action: 'order_blocks', group: field } end + protected + def block_available?(block) controller.class.available_blocks.keys.include? block end + def construct(block) + if block_available? block + render partial: 'block', locals: { block_name: block } + elsif block.respond_to? :to_ary + render partial: 'block_textilizable', locals: { block_name: block } + end + end end From 66499965ff27d2d37afc38f33080c7e63ccf4e64 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Mon, 20 Apr 2015 16:40:46 +0200 Subject: [PATCH 05/11] use the toolbar component --- app/views/my_projects_overviews/page_layout.html.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/my_projects_overviews/page_layout.html.erb b/app/views/my_projects_overviews/page_layout.html.erb index c51b99a597..8d58616c68 100644 --- a/app/views/my_projects_overviews/page_layout.html.erb +++ b/app/views/my_projects_overviews/page_layout.html.erb @@ -109,7 +109,7 @@ function addBlock() { <% content_for :toolbar do %> -
  • +
  • <%= styled_form_tag({:action => "add_block"}, :id => "block-form") do %> <%= styled_select_tag 'block', ("" + options_for_select(block_options)).html_safe, @@ -119,7 +119,7 @@ function addBlock() { %> <% end %>
  • -
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %>
  • +
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %>
  • <% end %>

    <%=l(:label_overview)%>

    From 62ade9ef4c90c8fd4a7bdbdb3166decf6f7f9c54 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Mon, 20 Apr 2015 17:54:13 +0200 Subject: [PATCH 06/11] refactor javascript into own file --- .../my_project_page/my_project_page.js | 142 +++++++++++++++--- app/helpers/my_projects_overviews_helper.rb | 25 ++- .../page_layout.html.erb | 106 +------------ 3 files changed, 141 insertions(+), 132 deletions(-) diff --git a/app/assets/javascripts/my_project_page/my_project_page.js b/app/assets/javascripts/my_project_page/my_project_page.js index 8c03c92e84..f37ffe77cd 100644 --- a/app/assets/javascripts/my_project_page/my_project_page.js +++ b/app/assets/javascripts/my_project_page/my_project_page.js @@ -1,7 +1,7 @@ //-- copyright // OpenProject My Project Page Plugin // -// Copyright (C) 2011-2014 the OpenProject Foundation (OPF) +// Copyright (C) 2011-2015 the OpenProject Foundation (OPF) // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License version 3. @@ -20,23 +20,131 @@ /*globals jQuery, I18n*/ -var MyProjectPage = (function ($) { - var init; +(function($) { + // $ is prototype + // @see app/views/my_projects_overviews/page_layout.html.erb - init = function () { - $('#users_per_role .all').click(function () { - $('#users_per_role').html(''); - }); + function recreateSortables() { + var lists = $$('.list-position'), + containedPositions = function() { + var positions = _.map(lists, function(list) { + return list.readAttribute('id') + }); + return _.uniq(positions); + }(), + destroy = function destroy(list) { + var id = list.readAttribute('id'); + Sortable.destroy(id); + }, + create = function create(list) { + var id = list.readAttribute('id'), + url = list.readAttribute('data-ajax-url'); + Sortable.create(id, { + constraint: false, + dropOnEmpty: true, + handle: 'handle', + onUpdate: function updatePosition() { + new Ajax. Request(url, { + asynchronous: true, + evalScripts: true, + parameters: Sortable.serialize(id) + }); + }, + containment: containedPositions, + only: 'mypage-box', + tag: 'div' + }); + }; - $.ajaxAppend({ - trigger: '.all', - indicator_class: 'ajax-indicator', - load_target: '#users_per_role', - loading_text: I18n.t("js.ajax.loading"), - loading_class: 'box loading' - }); - }; + lists.each(destroy); + lists.each(create); + } + + function updateSelect() { + s = $('block-select') + for (var i = 0; i < s.options.length; i++) { + if ($('block_' + s.options[i].value)) { + s.options[i].disabled = true; + } else { + s.options[i].disabled = false; + } + } + s.options[0].selected = true; + } + + function afterAddBlock(response) { + recreateSortables(); + updateSelect(); + editTextilizable(extractBlockName(response)); + new Effect.ScrollTo('list-hidden'); + } + + function extractBlockName(response) { + return response.responseText.match(/id="block_(.*?)"/)[1]; + } + + function removeBlock(block) { + Effect.DropOut(block); + $(block).remove(); + updateSelect(); + } + + function resetTextilizable(name) { + $("textile_" + name).setValue(window["page_layout-textile" + name] + ""); + toggleTextilizableVisibility(name); + return false; + } + + function editTextilizable(name) { + var textile_name = $("textile_" + name); + if (textile_name != null) { + window["page_layout-textile" + name] = textile_name.getValue(); + toggleTextilizableVisibility(name); + } + return false; + } - $('document').ready(init); + function toggleTextilizableVisibility(name) { + $(name + '-form-div').toggle(); + $(name + '-preview-div').toggle(); + $(name + '-text').toggle(); + } + function addBlock() { + new Ajax.Updater('list-hidden', + $('block-form').action, + { insertion: 'top', + onComplete: afterAddBlock, + parameters: Form.serialize('block-form'), + evalScripts:true + }); -}(jQuery)); + return false; + } + + // prototype end + + (function($) { + // from here on, '$' is jQuery + + $(function() { + $('#users_per_role .all').click(function () { + $('#users_per_role').html(''); + }); + + $.ajaxAppend({ + trigger: '.all', + indicator_class: 'ajax-indicator', + load_target: '#users_per_role', + loading_text: I18n.t("js.ajax.loading"), + loading_class: 'box loading' + }); + + // this was previously bound in the template + $('#block-select').on('change', addBlock); + + //initialize the fun! + recreateSortables(); + updateSelect(); + }); + }(jQuery)) +}($)); diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 9bd3bb7df7..2ce3241171 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -42,23 +42,16 @@ module MyProjectsOverviewsHelper end def grid_field(name) - css_classes = %w(block-receiver) + [name] - content_tag :div, id: "list-#{name}", class: css_classes do + css_classes = %w(block-receiver list-position) + [name] + data = { + :'ajax-url' => ajax_url(name), + position: name + } + content_tag :div, id: "list-#{name}", class: css_classes, data: data do ActiveSupport::SafeBuffer.new(blocks[name].map { |b| construct b }.join) end end - def sortable_box(field) - sortable_element "list-#{field}", - tag: 'div', - only: 'mypage-box', - handle: 'handle', - dropOnEmpty: true, - containment: field_list.collect { |x| "list-#{x}" }, - constraint: false, - url: { action: 'order_blocks', group: field } - end - protected def block_available?(block) @@ -72,4 +65,10 @@ module MyProjectsOverviewsHelper render partial: 'block_textilizable', locals: { block_name: block } end end + + def ajax_url(name) + url_for controller: '/my_projects_overviews', + action: 'order_blocks', + group: name + end end diff --git a/app/views/my_projects_overviews/page_layout.html.erb b/app/views/my_projects_overviews/page_layout.html.erb index 8d58616c68..8405e7ea10 100644 --- a/app/views/my_projects_overviews/page_layout.html.erb +++ b/app/views/my_projects_overviews/page_layout.html.erb @@ -19,107 +19,17 @@ See doc/COPYRIGHT.md for more details. ++#%> - - <% content_for :toolbar do %>
  • <%= styled_form_tag({:action => "add_block"}, :id => "block-form") do %> <%= styled_select_tag 'block', ("" + options_for_select(block_options)).html_safe, :id => "block-select", - :onChange => "addBlock();", class: 'form--select' %> <% end %>
  • -
  • <%= link_to l(:button_back), {:action => 'index'}, :class => 'button' %>
  • +
  • <%= link_to l(:button_back), {:action => 'index'}, class: 'button' %>
  • <% end %>

    <%=l(:label_overview)%>

    @@ -141,23 +51,15 @@ function addBlock() {

    <%=l(:label_hidden_elements) %>

    -
    - <% hidden_fields.each do |f| %> - <%= grid_field f %> - <% end %> -
    +<% hidden_fields.each do |f| %> + <%= grid_field f %> +<% end %>

    <%= l(:label_file_plural) %>

    <%= render(:partial => "page_layout_attachments") %>
    -<% field_list.each do |field| %> - <%= sortable_box field %> -<% end %> - -<%= javascript_tag "updateSelect()" %> - <% content_for :header_tags do %> <%= javascript_include_tag "my_project_page/my_project_page" %> <%= stylesheet_link_tag "my_project_page/my_projects_overview", :media => 'all' %> From b38c97c34fb891cc5d3147d278aa8bda66c1c727 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 21 Apr 2015 09:38:32 +0200 Subject: [PATCH 07/11] remove block via rendered js I couldn't figure put how the callback worked for sortable so I just used the Rails way to *incoming pun* sort it out. --- .../my_project_page/my_project_page.js | 15 ++++++++------- .../my_projects_overviews_controller.rb | 5 ++--- app/views/my_projects_overviews/_block.html.erb | 4 ++-- .../my_projects_overviews/remove_block.js.erb | 7 +++++++ 4 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 app/views/my_projects_overviews/remove_block.js.erb diff --git a/app/assets/javascripts/my_project_page/my_project_page.js b/app/assets/javascripts/my_project_page/my_project_page.js index f37ffe77cd..c6d96b87a1 100644 --- a/app/assets/javascripts/my_project_page/my_project_page.js +++ b/app/assets/javascripts/my_project_page/my_project_page.js @@ -83,12 +83,6 @@ return response.responseText.match(/id="block_(.*?)"/)[1]; } - function removeBlock(block) { - Effect.DropOut(block); - $(block).remove(); - updateSelect(); - } - function resetTextilizable(name) { $("textile_" + name).setValue(window["page_layout-textile" + name] + ""); toggleTextilizableVisibility(name); @@ -139,12 +133,19 @@ loading_class: 'box loading' }); - // this was previously bound in the template + // this was previously bound in the template directly $('#block-select').on('change', addBlock); //initialize the fun! recreateSortables(); updateSelect(); + + // TODO: this is exceptionally _not_ fun + // this attaches the update method to the window in order for it + // being callable after removal + window.myPage = window.myPage || { + updateSelect: updateSelect + }; }); }(jQuery)) }($)); diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 97fde3418a..89c11b9b06 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -91,10 +91,9 @@ class MyProjectsOverviewsController < ApplicationController # Remove a block to user's page # params[:block] : id of the block to remove def remove_block - block = param_to_block(params[:block]) - %w(top left right hidden).each {|f| overview.send(f).delete block } + @block = param_to_block(params[:block]) + %w(top left right hidden).each {|f| overview.send(f).delete @block } overview.save! - render :nothing => true end # Change blocks order on user's page diff --git a/app/views/my_projects_overviews/_block.html.erb b/app/views/my_projects_overviews/_block.html.erb index 34d4f9bbef..12f8d8b6d6 100644 --- a/app/views/my_projects_overviews/_block.html.erb +++ b/app/views/my_projects_overviews/_block.html.erb @@ -27,8 +27,8 @@ See doc/COPYRIGHT.md for more details. <%= link_to_remote l(:button_delete), { :confirm => l(:label_confirm_delete), :url => { :action => "remove_block", :block => block_name }, - :complete => "removeBlock('block_#{block_name.dasherize}')" }, - :class => "icon icon-delete" + :class => "icon icon-delete" + } %> <% end %> diff --git a/app/views/my_projects_overviews/remove_block.js.erb b/app/views/my_projects_overviews/remove_block.js.erb new file mode 100644 index 0000000000..28f1d15051 --- /dev/null +++ b/app/views/my_projects_overviews/remove_block.js.erb @@ -0,0 +1,7 @@ +(function($) { + var block = $('#block_' + '<%= @block.dasherize %>'); + block.fadeOut('fast', function() { + block.remove(); + myPage.updateSelect(); + }); +}(jQuery)) From 5ff463552a53b9c97c166e846e3781d18788d84b Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 21 Apr 2015 09:39:15 +0200 Subject: [PATCH 08/11] move header tags and title to the top --- .../my_projects_overviews/page_layout.html.erb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/views/my_projects_overviews/page_layout.html.erb b/app/views/my_projects_overviews/page_layout.html.erb index 8405e7ea10..f92931a9d6 100644 --- a/app/views/my_projects_overviews/page_layout.html.erb +++ b/app/views/my_projects_overviews/page_layout.html.erb @@ -18,6 +18,13 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. See doc/COPYRIGHT.md for more details. ++#%> +<% html_title(l(:label_overview)) -%> + +<% content_for :header_tags do %> + <%= javascript_include_tag "my_project_page/my_project_page" %> + <%= stylesheet_link_tag "my_project_page/my_projects_overview", :media => 'all' %> + <% heads_for_wiki_formatter %> +<% end %> <% content_for :toolbar do %>
  • @@ -60,10 +67,5 @@ See doc/COPYRIGHT.md for more details. <%= render(:partial => "page_layout_attachments") %> -<% content_for :header_tags do %> - <%= javascript_include_tag "my_project_page/my_project_page" %> - <%= stylesheet_link_tag "my_project_page/my_projects_overview", :media => 'all' %> - <% heads_for_wiki_formatter %> -<% end %> -<% html_title(l(:label_overview)) -%> + From 8cc7e9e67a4f34ec4b7261a5ce13f6f387f460a2 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 21 Apr 2015 10:56:23 +0200 Subject: [PATCH 09/11] fix the handling for textilized (generated content) blocks --- .../my_project_page/my_project_page.js | 94 ++++++++++++------- .../my_project_page/my_projects_overview.sass | 1 + .../my_projects_overviews_controller.rb | 1 - app/helpers/my_projects_overviews_helper.rb | 21 ++++- .../_block_textilizable.html.erb | 11 +-- .../my_projects_overviews/order_blocks.js.erb | 2 + .../my_projects_overviews/remove_block.js.erb | 2 +- 7 files changed, 88 insertions(+), 44 deletions(-) create mode 100644 app/views/my_projects_overviews/order_blocks.js.erb diff --git a/app/assets/javascripts/my_project_page/my_project_page.js b/app/assets/javascripts/my_project_page/my_project_page.js index c6d96b87a1..89d852041a 100644 --- a/app/assets/javascripts/my_project_page/my_project_page.js +++ b/app/assets/javascripts/my_project_page/my_project_page.js @@ -18,7 +18,8 @@ // See doc/COPYRIGHT.md for more details. //++ -/*globals jQuery, I18n*/ +/* globals jQuery, $$, $, Sortable, Effect, Form */ +/* jshint camelcase: false */ (function($) { // $ is prototype @@ -26,12 +27,12 @@ function recreateSortables() { var lists = $$('.list-position'), - containedPositions = function() { + containedPositions = (function() { var positions = _.map(lists, function(list) { - return list.readAttribute('id') + return list.readAttribute('id'); }); return _.uniq(positions); - }(), + }()), destroy = function destroy(list) { var id = list.readAttribute('id'); Sortable.destroy(id); @@ -44,7 +45,7 @@ dropOnEmpty: true, handle: 'handle', onUpdate: function updatePosition() { - new Ajax. Request(url, { + new Ajax.Request(url, { asynchronous: true, evalScripts: true, parameters: Sortable.serialize(id) @@ -61,41 +62,41 @@ } function updateSelect() { - s = $('block-select') - for (var i = 0; i < s.options.length; i++) { - if ($('block_' + s.options[i].value)) { - s.options[i].disabled = true; - } else { - s.options[i].disabled = false; - } + var s = $('block-select'); + for (var i = 0; i < s.options.length; i++) { + if ($('block_' + s.options[i].value)) { + s.options[i].disabled = true; + } else { + s.options[i].disabled = false; } - s.options[0].selected = true; + } + s.options[0].selected = true; } function afterAddBlock(response) { - recreateSortables(); - updateSelect(); - editTextilizable(extractBlockName(response)); - new Effect.ScrollTo('list-hidden'); + recreateSortables(); + updateSelect(); + editTextilizable(extractBlockName(response)); + new Effect.ScrollTo('list-hidden'); } function extractBlockName(response) { - return response.responseText.match(/id="block_(.*?)"/)[1]; + return response.responseText.match(/id="block_(.*?)"/)[1]; } function resetTextilizable(name) { - $("textile_" + name).setValue(window["page_layout-textile" + name] + ""); - toggleTextilizableVisibility(name); - return false; + $('textile_' + name).setValue(window['page_layout-textile' + name] + ''); + toggleTextilizableVisibility(name); + return false; } function editTextilizable(name) { - var textile_name = $("textile_" + name); - if (textile_name != null) { - window["page_layout-textile" + name] = textile_name.getValue(); - toggleTextilizableVisibility(name); - } - return false; + var textile_name = $('textile_' + name); + if (textile_name !== null) { + window['page_layout-textile' + name] = textile_name.getValue(); + toggleTextilizableVisibility(name); + } + return false; } function toggleTextilizableVisibility(name) { @@ -129,23 +130,52 @@ trigger: '.all', indicator_class: 'ajax-indicator', load_target: '#users_per_role', - loading_text: I18n.t("js.ajax.loading"), + loading_text: I18n.t('js.ajax.loading'), loading_class: 'box loading' }); // this was previously bound in the template directly $('#block-select').on('change', addBlock); - //initialize the fun! + // we need to rebind some of the links constantly, as the content is generated + // on the page + function updateBlockLinks() { + function getBlockName(element) { + var blockName = element.data('block-name'); + if (!blockName) { + throw new Error('no block name found for element'); + } + return blockName; + } + + // bind textilizable block links + $('a.reset-textilizable').on('click', function(e) { + e.preventDefault(); + resetTextilizable(getBlockName($(this))); + }); + + $('a.edit-textilizable').on('click', function(e) { + e.preventDefault(); + editTextilizable(getBlockName($(this))); + }); + } + + // initialize the fun! (prototype) recreateSortables(); updateSelect(); + // moar fun + updateBlockLinks(); + + //these are generated blocks, so we have to watch the links inside them + // TODO: this is exceptionally _not_ fun // this attaches the update method to the window in order for it - // being callable after removal + // being callable after removal of a block window.myPage = window.myPage || { - updateSelect: updateSelect + updateSelect: updateSelect, + updateBlockLinks: updateBlockLinks }; }); - }(jQuery)) + }(jQuery)); }($)); diff --git a/app/assets/stylesheets/my_project_page/my_projects_overview.sass b/app/assets/stylesheets/my_project_page/my_projects_overview.sass index 7981fe6cea..5f9d46c1eb 100644 --- a/app/assets/stylesheets/my_project_page/my_projects_overview.sass +++ b/app/assets/stylesheets/my_project_page/my_projects_overview.sass @@ -29,5 +29,6 @@ div.overview min-height: 32px // TODO: this fixes an issue which currently breaks the layout // It has to be removed once it is fixed upstream + // @see https://github.com/zurb/foundation-apps/issues/575 &.left, &.right @extend .medium-6 diff --git a/app/controllers/my_projects_overviews_controller.rb b/app/controllers/my_projects_overviews_controller.rb index 89c11b9b06..f0fbc3febd 100644 --- a/app/controllers/my_projects_overviews_controller.rb +++ b/app/controllers/my_projects_overviews_controller.rb @@ -113,7 +113,6 @@ class MyProjectsOverviewsController < ApplicationController overview.update_attribute(group, group_items) end end - render :nothing => true end def param_to_block(param) diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 2ce3241171..6e4f194549 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -38,7 +38,7 @@ module MyProjectsOverviewsHelper if MyProjectsOverviewsHelper.const_defined? constant_name return MyProjectsOverviewsHelper.const_get constant_name end - raise NoMethodError + raise NoMethodError.new("tried to call method #{name}, but was not found!") end def grid_field(name) @@ -59,10 +59,11 @@ module MyProjectsOverviewsHelper end def construct(block) + if block.is_a? Array + return render_textilized block + end if block_available? block - render partial: 'block', locals: { block_name: block } - elsif block.respond_to? :to_ary - render partial: 'block_textilizable', locals: { block_name: block } + return render_normal block end end @@ -71,4 +72,16 @@ module MyProjectsOverviewsHelper action: 'order_blocks', group: name end + + def render_textilized(block) + render partial: 'block_textilizable', locals: { + block_name: block.first, + block_title: block[1], + textile: block.last + } + end + + def render_normal(block) + render partial: 'block', locals: { block_name: block } + end end diff --git a/app/views/my_projects_overviews/_block_textilizable.html.erb b/app/views/my_projects_overviews/_block_textilizable.html.erb index 2cc70a118c..a7bf96df65 100644 --- a/app/views/my_projects_overviews/_block_textilizable.html.erb +++ b/app/views/my_projects_overviews/_block_textilizable.html.erb @@ -24,8 +24,8 @@ See doc/COPYRIGHT.md for more details. <% content_for block_name do %>
    - <%= l(:button_edit) %> + <%= l(:button_edit) %> <%= link_to_remote l(:button_delete), { :confirm => l(:label_confirm_delete), :url => { :action => "remove_block", :block => block_name }, - :complete => "removeBlock('block_#{block_name.dasherize}')" }, - :class => "icon icon-delete" + :class => "icon icon-delete" + } %>
    diff --git a/app/views/my_projects_overviews/order_blocks.js.erb b/app/views/my_projects_overviews/order_blocks.js.erb new file mode 100644 index 0000000000..584a30fdb9 --- /dev/null +++ b/app/views/my_projects_overviews/order_blocks.js.erb @@ -0,0 +1,2 @@ +// rebind some of the links if the block is textilizable +myPage.updateBlockLinks(); diff --git a/app/views/my_projects_overviews/remove_block.js.erb b/app/views/my_projects_overviews/remove_block.js.erb index 28f1d15051..cffcd5ab19 100644 --- a/app/views/my_projects_overviews/remove_block.js.erb +++ b/app/views/my_projects_overviews/remove_block.js.erb @@ -1,5 +1,5 @@ (function($) { - var block = $('#block_' + '<%= @block.dasherize %>'); + var block = $('#block_' + '<%= @block.is_a?(Array) ? @block.first.dasherize : @block.dasherize %>'); block.fadeOut('fast', function() { block.remove(); myPage.updateSelect(); From 92cc2819015b956d3b33ecf91c5cb702fd9c174e Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 21 Apr 2015 10:58:21 +0200 Subject: [PATCH 10/11] clean up and note --- app/assets/javascripts/my_project_page/my_project_page.js | 1 + app/helpers/my_projects_overviews_helper.rb | 1 + 2 files changed, 2 insertions(+) diff --git a/app/assets/javascripts/my_project_page/my_project_page.js b/app/assets/javascripts/my_project_page/my_project_page.js index 89d852041a..abb03625f0 100644 --- a/app/assets/javascripts/my_project_page/my_project_page.js +++ b/app/assets/javascripts/my_project_page/my_project_page.js @@ -20,6 +20,7 @@ /* globals jQuery, $$, $, Sortable, Effect, Form */ /* jshint camelcase: false */ +/* jshint nonew: false */ (function($) { // $ is prototype diff --git a/app/helpers/my_projects_overviews_helper.rb b/app/helpers/my_projects_overviews_helper.rb index 6e4f194549..ac18dd67f1 100644 --- a/app/helpers/my_projects_overviews_helper.rb +++ b/app/helpers/my_projects_overviews_helper.rb @@ -33,6 +33,7 @@ module MyProjectsOverviewsHelper TOP + MIDDLE end + # TODO: potentially dangerous, is there a better way? (via define_method?) def method_missing(name) constant_name = name.to_s.gsub('_fields', '').upcase if MyProjectsOverviewsHelper.const_defined? constant_name From dfda40c7eaec237885d5ea82b910e89f6a07d276 Mon Sep 17 00:00:00 2001 From: Florian Kraft Date: Tue, 21 Apr 2015 11:07:47 +0200 Subject: [PATCH 11/11] please the hound --- app/assets/javascripts/my_project_page/my_project_page.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/assets/javascripts/my_project_page/my_project_page.js b/app/assets/javascripts/my_project_page/my_project_page.js index abb03625f0..c75f23cf0b 100644 --- a/app/assets/javascripts/my_project_page/my_project_page.js +++ b/app/assets/javascripts/my_project_page/my_project_page.js @@ -18,7 +18,7 @@ // See doc/COPYRIGHT.md for more details. //++ -/* globals jQuery, $$, $, Sortable, Effect, Form */ +/* globals jQuery, $$, $, Sortable, Effect, Form, Ajax, I18n, _ */ /* jshint camelcase: false */ /* jshint nonew: false */