From e2f753a4cb6c299fc6440ae94e20891a5a0c77cb Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Thu, 7 Mar 2013 11:01:20 +0100 Subject: [PATCH] =?utf8?q?Textbl=C3=B6cke=20bearbeiten,=20verschieben:=20v?= =?utf8?q?erschiedene=20Fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpec.pm | 7 +- SL/Controller/RequirementSpecTextBlock.pm | 87 ++++++++++--- SL/Presenter/RequirementSpecTextBlock.pm | 2 +- css/requirement_spec.css | 4 +- js/requirement_spec.js | 57 ++++---- locale/de/all | 1 + templates/webpages/requirement_spec/show.html | 19 +-- templates/webpages/requirement_spec/tree.html | 122 ------------------ .../requirement_spec_text_block/_form.html | 17 ++- 9 files changed, 119 insertions(+), 197 deletions(-) delete mode 100644 templates/webpages/requirement_spec/tree.html diff --git a/SL/Controller/RequirementSpec.pm b/SL/Controller/RequirementSpec.pm index 1f6ba7fa6..2c1139e13 100644 --- a/SL/Controller/RequirementSpec.pm +++ b/SL/Controller/RequirementSpec.pm @@ -23,7 +23,7 @@ use Rose::Object::MakeMethods::Generic ); __PACKAGE__->run_before('setup'); -__PACKAGE__->run_before('load_requirement_spec', only => [ qw( edit update show destroy tree) ]); +__PACKAGE__->run_before('load_requirement_spec', only => [ qw( edit update show destroy) ]); __PACKAGE__->run_before('load_select_options', only => [ qw(new edit create update list) ]); __PACKAGE__->run_before('load_search_select_options', only => [ qw( list) ]); @@ -118,11 +118,6 @@ sub action_reorder { $self->render('1;', { type => 'js', inline => 1 }); } -sub action_tree { - my ($self) = @_; - my $r = $self->render('requirement_spec/tree', now => DateTime->now); -} - # # filters # diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index e0529da1c..4b42841cf 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -4,6 +4,8 @@ use strict; use parent qw(SL::Controller::Base); +use Time::HiRes (); + use SL::ClientJS; use SL::DB::RequirementSpec; use SL::DB::RequirementSpecPredefinedText; @@ -14,7 +16,8 @@ use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( - scalar => [ qw(requirement_spec text_block) ], + scalar => [ qw(requirement_spec text_block) ], + 'scalar --get_set_init' => [ qw(predefined_texts) ], ); __PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit ajax_update ajax_delete dragged_and_dropped)]); @@ -30,7 +33,7 @@ sub action_ajax_list { my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}); my $new_where; - if ($::form->{clicked_type} =~ m/^textblocks-(front|back)/) { + if ($::form->{clicked_type} =~ m/^text-blocks-(front|back)/) { $new_where = $1 eq 'front' ? 0 : 1; } else { @@ -66,13 +69,13 @@ sub action_ajax_edit { ->val('#current_content_id', $self->text_block->id); } - my $predefined_texts = SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted; - my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, PREDEFINED_TEXTS => $predefined_texts); + my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }); $js->hide('#text-block-' . $self->text_block->id) ->remove('#edit_text_block_' . $self->text_block->id . '_form') ->insertAfter($html, '#text-block-' . $self->text_block->id) ->jstree->select_node('#tree', '#tb-' . $self->text_block->id) + ->focus('#edit_text_block_' . $self->text_block->id . '_title') ->render($self); } @@ -97,6 +100,28 @@ sub action_ajax_update { ->render($self); } +sub action_ajax_create { + # TODO: ajax_create + my ($self, %params) = @_; + + my $prefix = $::form->{form_prefix} || 'text_block'; + my $attributes = $::form->{$prefix} || {}; + + foreach (qw(requirement_spec_id output_position)) { + delete $attributes->{$_} if !defined $attributes->{$_}; + } + + $self->text_block->update_attributes(%{ $attributes }); + + my $html = $self->render('requirement_spec_text_block/_text_block', { output => 0 }, text_block => $self->text_block); + + SL::ClientJS->new + ->remove('#' . $prefix . '_form') + ->replaceWith('#text-block-' . $self->text_block->id, $html) + ->jstree->rename_node('#tree', '#tb-' . $self->text_block->id, $self->text_block->title) + ->render($self); +} + sub action_ajax_delete { my ($self) = @_; @@ -116,25 +141,55 @@ sub action_ajax_delete { ->render($self); } +sub action_ajax_add { + my ($self) = @_; + + my $js = SL::ClientJS->new; + + my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; + my $new_where = $self->output_position_from_id($::form->{id}) // $::form->{output_position}; + + if ($new_where != $current_where) { + my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where, requirement_spec_id => $::form->{requirement_spec_id} ]); + my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); + + $js->html('#column-content', $html); + } + + $self->text_block(SL::DB::RequirementSpecTextBlock->new( + requirement_spec_id => $::form->{requirement_spec_id}, + output_position => $::form->{output_position}, + )); + + my $id_base = join('_', 'new_text_block', Time::HiRes::gettimeofday(), int rand 1000000000000); + my $html = $self->render('requirement_spec_text_block/_form', { output => 0 }, id_base => $id_base); + + $js->action($::form->{id} ? 'insertAfter' : 'appendTo', $html, '#text-block-' . ($::form->{id} || 'list')) + ->focus('#' . $id_base . '_title') + ->render($self); +} + sub action_dragged_and_dropped { my ($self) = @_; my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter"; my $dropped_text_block = $position =~ m/^ (?: before | after ) $/x ? SL::DB::RequirementSpecTextBlock->new(id => $::form->{dropped_id})->load : undef; - my $dropped_type = $position ne 'last' ? undef : $::form->{dropped_type} =~ m/^ textblocks- (?:front|back) $/x ? $::form->{dropped_type} : die "Unknown 'dropped_type' parameter"; + my $dropped_type = $position ne 'last' ? undef : $::form->{dropped_type} =~ m/^ text-blocks- (?:front|back) $/x ? $::form->{dropped_type} : die "Unknown 'dropped_type' parameter"; my $old_where = $self->text_block->output_position; $self->text_block->db->do_transaction(sub { 1; $self->text_block->remove_from_list; - $self->text_block->output_position($position =~ m/before|after/ ? $dropped_text_block->output_position : $::form->{dropped_type} eq 'textblocks-front' ? 0 : 1); + $self->text_block->output_position($position =~ m/before|after/ ? $dropped_text_block->output_position : $::form->{dropped_type} eq 'text-blocks-front' ? 0 : 1); $self->text_block->add_to_list(position => $position, reference => $dropped_text_block ? $dropped_text_block->id : undef); }); - return $self->render(\'', { type => 'json' }) if $::form->{current_content_type} !~ m/^textblock/; + # $::lxdebug->dump(0, "form", $::form); - my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}); + return $self->render(\'', { type => 'json' }) if $::form->{current_content_type} !~ m/^text-block/; + + my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; my $new_where = $self->text_block->output_position; my $id = $self->text_block->id; my $js = SL::ClientJS->new; @@ -146,7 +201,7 @@ sub action_dragged_and_dropped { my $text_blocks = SL::DB::Manager::RequirementSpecTextBlock->get_all_sorted(where => [ output_position => $new_where ]); my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $new_where); - $js->val('#current_content_type', 'textblocks-' . ($new_where == 0 ? 'front' : 'back')) + $js->val('#current_content_type', 'text-blocks-' . ($new_where == 0 ? 'front' : 'back')) ->html('#column-content', $html); } else { @@ -197,16 +252,18 @@ sub load_requirement_spec_text_block { sub output_position_from_id { my ($self, $id, $type, %params) = @_; - if (!$id) { - return $params{default} unless $type =~ m/-(front|back)/; - return $1 eq 'front' ? 0 : 1; + if ($type) { + return $1 eq 'front' ? 0 : 1 if $type =~ m/-(front|back)$/; + return undef if $type !~ m/text-block/; } my $text_block = SL::DB::Manager::RequirementSpecTextBlock->find_by(id => $id); - return $params{default} unless $text_block; - return $text_block->output_position unless $params{as} eq 'text'; - return 1 == $text_block->output_position ? 'front' : 'back'; + return $text_block ? $text_block->output_position : undef; +} + +sub init_predefined_texts { + return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted; } 1; diff --git a/SL/Presenter/RequirementSpecTextBlock.pm b/SL/Presenter/RequirementSpecTextBlock.pm index 8e2eb81a1..dc045ff31 100644 --- a/SL/Presenter/RequirementSpecTextBlock.pm +++ b/SL/Presenter/RequirementSpecTextBlock.pm @@ -16,7 +16,7 @@ sub requirement_spec_text_block_jstree_data { return { data => $text_block->title || '', - metadata => { id => $text_block->id, type => 'textblock' }, + metadata => { id => $text_block->id, type => 'text-block' }, attr => { id => "tb-" . $text_block->id, href => $params{href} || '#', class => 'text-block-context-menu' }, }; } diff --git a/css/requirement_spec.css b/css/requirement_spec.css index 82b895e41..2901452c3 100644 --- a/css/requirement_spec.css +++ b/css/requirement_spec.css @@ -14,11 +14,11 @@ table.rs_input_field input, table.rs_input_field select { #tree-column { float: left; width: 25%; - border-right: 1px solid black; } #content-column { - float: left; + float: right; + width: 74%; padding-left: 10px; } diff --git a/js/requirement_spec.js b/js/requirement_spec.js index f7b52e642..de3e8d531 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -6,13 +6,13 @@ function requirement_spec_tree_check_move(data) { // console.debug("dragged " + dragged_type + " dropped " + dropped_type + " dir " + data.p); - if ((dragged_type == "sections") || (dragged_type == "textblocks-front") || (dragged_type == "textblocks-back")) + if ((dragged_type == "sections") || (dragged_type == "text-blocks-front") || (dragged_type == "text-blocks-back")) return false; - if (dragged_type == "textblock") { - if ((dropped_type == "textblocks-front") || (dropped_type == "textblocks-back")) + if (dragged_type == "text-block") { + if ((dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back")) return (data.p == "inside") || (data.p == "last"); - if (dropped_type == "textblock") + if (dropped_type == "text-block") return (data.p == "before") || (data.p == "after"); return false; @@ -28,7 +28,7 @@ function requirement_spec_tree_check_move(data) { } // dragged_type == (sub) function blocks - if ((dropped_type == "textblock") || (dropped_type == "textblocks-front") || (dropped_type == "textblocks-back")) + if ((dropped_type == "text-block") || (dropped_type == "text-blocks-front") || (dropped_type == "text-blocks-back")) return false; var dropped_depth = dropped_type == "sections" ? 0 : dropped_type == "section" ? 1 : data.r.parent().parent().data('type') != "functionblock" ? 2 : 3; @@ -47,7 +47,7 @@ function requirement_spec_tree_node_moved(event) { var move_obj = $.jstree._reference('#tree')._get_move(); var dragged = move_obj.o; var dropped = move_obj.r; - var controller = dragged.data("type") == "textblock" ? "RequirementSpecTextBlock" : "RequirementSpecItem"; + var controller = dragged.data("type") == "text-block" ? "RequirementSpecTextBlock" : "RequirementSpecItem"; var data = { action: controller + "/dragged_and_dropped", requirement_spec_id: $('#requirement_spec_id').val(), @@ -81,7 +81,7 @@ function requirement_spec_tree_node_clicked(event) { var url = 'controller.pl?action=' $.get('controller.pl', { - action: (/^textblock/ ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js', + action: (/^text-block/ ? 'RequirementSpecTextBlock' : 'RequirementSpecItem') + '/ajax_list.js', requirement_spec_id: $('#requirement_spec_id').val(), current_content_type: $('#current_content_type').val(), current_content_id: $('#current_content_id').val(), @@ -137,26 +137,26 @@ function cancel_section_form(id) { } function find_text_block_id(clicked_elt) { - console.log("id: " + $(clicked_elt).attr('id')); + // console.log("id: " + $(clicked_elt).attr('id')); var id = $(clicked_elt).attr('id'); if (/^text-block-\d+$/.test(id)) { - console.log("find_text_block_id: case 1: " + id.substr(11)); + // console.log("find_text_block_id: case 1: " + id.substr(11)); return id.substr(11) * 1; } id = $(clicked_elt).closest("[id*=text-block-]").attr('id') if (/^text-block-\d+$/.test(id)) { - console.log("find_text_block_id: case 2: " + id.substr(11)); + // console.log("find_text_block_id: case 2: " + id.substr(11)); return id.substr(11) * 1; } id = $(clicked_elt).closest("[id*=tb-]").attr('id') if (/^tb-\d+$/.test(id)) { - console.log("find_text_block_id: case 3: " + id.substr(3)); + // console.log("find_text_block_id: case 3: " + id.substr(3)); return id.substr(3) * 1; } - console.log("find_text_block_id: case undef"); + // console.log("find_text_block_id: case undef"); return undefined; } @@ -166,8 +166,8 @@ function find_text_block_output_position(clicked_elt) { return output_position; var type = $(clicked_elt).closest('#tb-back,#tb-front').data('type'); - if (/^textblocks-(front|back)/.test(type)) - return type == "textblocks-front" ? 0 : 1; + if (/^text-blocks-(front|back)/.test(type)) + return type == "text-blocks-front" ? 0 : 1; return undefined; } @@ -176,42 +176,31 @@ function disable_edit_text_block_commands(key, opt) { return find_text_block_id(opt.$trigger) == undefined; } -function edit_text_block(key, opt) { +function standard_text_block_ajax_call(key, opt, other_data) { var data = { - action: "RequirementSpecTextBlock/ajax_edit", + action: "RequirementSpecTextBlock/ajax_" + key, + requirement_spec_id: $('#requirement_spec_id').val(), id: find_text_block_id(opt.$trigger), + output_position: find_text_block_output_position(opt.$trigger), current_content_type: $('#current_content_type').val(), current_content_id: $('#current_content_id').val() }; - $.post("controller.pl", data, eval_json_result); - return true; -} -function add_text_block(key, opt) { - return true; -} + $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result); -function delete_text_block(key, opt) { - var data = { - action: "RequirementSpecTextBlock/ajax_delete", - id: find_text_block_id(opt.$trigger), - current_content_type: $('#current_content_type').val(), - current_content_id: $('#current_content_id').val() - }; - $.post("controller.pl", data, eval_json_result); return true; } function submit_edit_text_block_form(id_base) { + var id = $('#' + id_base + '_id').val(); var url = "controller.pl?" + $('#' + id_base + '_form').serialize(); var data = { - action: 'RequirementSpecTextBlock/ajax_update', - id: $('#' + id_base + '_id').val(), + action: 'RequirementSpecTextBlock/ajax_' + (id ? 'update' : 'create'), + id: id, form_prefix: id_base }; - console.log("posting edit text block: " + url); - console.log(data); $.post(url, data, eval_json_result); + return true; } function cancel_edit_text_block_form(id_base) { diff --git a/locale/de/all b/locale/de/all index 05ea6f943..69093d947 100755 --- a/locale/de/all +++ b/locale/de/all @@ -892,6 +892,7 @@ $self->{texts} = { 'Edit section #1' => 'Abschnitt #1 bearbeiten', 'Edit templates' => 'Vorlagen bearbeiten', 'Edit text block' => 'Textblock bearbeiten', + 'Edit text block \'#1\'' => 'Textblock \'#1\' bearbeiten', 'Edit the Delivery Order' => 'Lieferschein bearbeiten', 'Edit the configuration for periodic invoices' => 'Konfiguration für wiederkehrende Rechnungen bearbeiten', 'Edit the currency names in order to rename them.' => 'Bearbeiten Sie den Namen, um eine Währung umzubennen.', diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index cb5cda92a..759add13f 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -12,14 +12,7 @@
-
-
-
- [% L.button_tag("new_section_form()", LxERP.t8("New section"), id="new-section-button") %] -
- -
- +
@@ -42,7 +35,7 @@ - - - - - - - - - - - - -
-
- - diff --git a/templates/webpages/requirement_spec_text_block/_form.html b/templates/webpages/requirement_spec_text_block/_form.html index ba93d3b78..40f430721 100644 --- a/templates/webpages/requirement_spec_text_block/_form.html +++ b/templates/webpages/requirement_spec_text_block/_form.html @@ -1,6 +1,15 @@ [%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% SET style="width: 500px" %] [% DEFAULT id_base = 'edit_text_block_' _ SELF.text_block.id %]
+

+ [%- IF SELF.text_block.id %] + [%- SET title = SELF.text_block.title || '(' _ LxERP.t8('No title yet') _ ')' %] + [%- LxERP.t8("Edit text block '#1'", title) %] + [%- ELSE %] + [%- LxERP.t8("Add text block") %] + [%- END %] +

+ [% L.hidden_tag(id_base _ '_id', SELF.text_block.id) %] [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.text_block.requirement_spec_id) %] [% L.hidden_tag(id_base _ '.output_position', SELF.text_block.output_position) %] @@ -11,11 +20,11 @@ [% L.input_tag(id_base _ '.title', SELF.text_block.title, style = style) %] - [%- IF PREDEFINED_TEXTS.size %] + [%- IF SELF.predefined_texts.size %] [%- LxERP.t8("Pre-defined Texts") %]: - [%- L.select_tag(id_base _ '_predefined_text_block', PREDEFINED_TEXTS, title_key='description', style=style) %] + [%- L.select_tag(id_base _ '_predefined_text_block', SELF.predefined_texts, title_key='description', style=style) %] [%- LxERP.t8("Insert") %] @@ -32,12 +41,12 @@ [%- LxERP.t8("Cancel") %]

-[%- IF PREDEFINED_TEXTS.size %] +[%- IF SELF.predefined_texts.size %]