From: Moritz Bunkus Date: Fri, 8 Mar 2013 14:33:19 +0000 (+0100) Subject: Textblöcke bearbeiten X-Git-Tag: release-3.2.0beta~467^2~243 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=602e604a5d2e2b07c142c3d47fc9a2337ca36301;p=kivitendo-erp.git Textblöcke bearbeiten --- diff --git a/SL/Controller/RequirementSpecTextBlock.pm b/SL/Controller/RequirementSpecTextBlock.pm index 6027cc555..21cf29e63 100644 --- a/SL/Controller/RequirementSpecTextBlock.pm +++ b/SL/Controller/RequirementSpecTextBlock.pm @@ -6,6 +6,7 @@ use parent qw(SL::Controller::Base); use SL::ClientJS; use SL::DB::RequirementSpec; +use SL::DB::RequirementSpecPredefinedText; use SL::DB::RequirementSpecTextBlock; use SL::Helper::Flash; use SL::JSON; @@ -16,7 +17,7 @@ use Rose::Object::MakeMethods::Generic scalar => [ qw(requirement_spec text_block) ], ); -__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(dragged_and_dropped)]); +__PACKAGE__->run_before('load_requirement_spec_text_block', only => [qw(ajax_edit update dragged_and_dropped)]); # # actions @@ -41,8 +42,8 @@ sub action_ajax_list { my $js = SL::ClientJS->new; if (!defined($current_where) || ($new_where != $current_where)) { - 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, nownow => DateTime->now_local); + 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) } @@ -50,6 +51,52 @@ sub action_ajax_list { $self->render($js); } +sub action_ajax_edit { + my ($self) = @_; + + my $js = SL::ClientJS->new; + + my $current_where = $self->output_position_from_id($::form->{current_content_id}, $::form->{current_content_type}) // -1; + if ($self->text_block->output_position != $current_where) { + my $text_blocks = $self->text_block->get_full_list; + my $html = $self->render('requirement_spec_text_block/ajax_list', { output => 0 }, TEXT_BLOCKS => $text_blocks, output_position => $self->text_block->output_position); + + $js->html('#column-content', $html) + ->val('#current_content_type', 'text-block') + ->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); + + $js->hide('#text-block-' . $self->text_block->id) + ->insertAfter($html, '#text-block-' . $self->text_block->id) + ->jstree->select_node('#tree', '#tb-' . $self->text_block->id) + ->render($self); +} + +sub action_update { + 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_dragged_and_dropped { my ($self) = @_; diff --git a/SL/Presenter.pm b/SL/Presenter.pm index 67b37df5c..ba24b8205 100644 --- a/SL/Presenter.pm +++ b/SL/Presenter.pm @@ -15,8 +15,8 @@ use SL::Presenter::Order; use SL::Presenter::Part; use SL::Presenter::Project; use SL::Presenter::Record; -use SL::Presenter::RequirementSpec; use SL::Presenter::RequirementSpecItem; +use SL::Presenter::RequirementSpecTextBlock; use SL::Presenter::SepaExport; use SL::Presenter::Text; use SL::Presenter::Tag; diff --git a/js/requirement_spec.js b/js/requirement_spec.js index fdd949e8e..a9e19e2af 100644 --- a/js/requirement_spec.js +++ b/js/requirement_spec.js @@ -1,6 +1,6 @@ /* Functions used for the requirement specs tree view */ -function check_move(data) { +function requirement_spec_tree_check_move(data) { var dragged_type = data.o.data('type'); var dropped_type = data.r.data('type'); @@ -42,7 +42,7 @@ function check_move(data) { return (2 <= dropped_depth) && ((dragged_depth + dropped_depth) <= 4); } -function node_moved(event) { +function requirement_spec_tree_node_moved(event) { console.debug("node moved"); var move_obj = $.jstree._reference('#tree')._get_move(); var dragged = move_obj.o; @@ -66,7 +66,7 @@ function node_moved(event) { return true; } -function node_clicked(event) { +function requirement_spec_tree_node_clicked(event) { var node = $.jstree._reference('#tree')._get_node(event.target); var type = node ? node.data('type') : undefined; @@ -82,6 +82,7 @@ function node_clicked(event) { var url = 'controller.pl?action=' $.get('controller.pl', { action: (/^textblock/ ? '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(), clicked_type: type, @@ -134,3 +135,88 @@ function submit_section_form(id) { function cancel_section_form(id) { $('#content-column').html('intentionally empty'); } + +function find_text_block_id(clicked_elt) { + 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)); + 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)); + 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)); + return id.substr(3) * 1; + } + + console.log("find_text_block_id: case undef"); + return undefined; +} + +function find_text_block_output_position(clicked_elt) { + var output_position = $(clicked_elt).closest('#text-block-list-container').find('#text_block_output_position').val(); + if (output_position) + 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; + + return undefined; +} + +function disable_edit_text_block_commands(key, opt) { + return find_text_block_id(opt.$trigger) == undefined; +} + +function edit_text_block(key, opt) { + var data = { + action: "RequirementSpecTextBlock/ajax_edit", + 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 add_text_block(key, opt) { + return true; +} + +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 url = "controller.pl?" + $('#' + id_base + '_form').serialize(); + var data = { + action: 'RequirementSpecTextBlock/update.js', + id: $('#' + id_base + '_id').val(), + form_prefix: id_base + }; + console.log("posting edit text block: " + url); + console.log(data); + $.post(url, data, eval_json_result); +} + +function cancel_edit_text_block_form(id_base) { + var id = $('#' + id_base + '_id').val(); + $('#' + id_base + '_form').remove(); + if (id) + $('#text-block-' + id).show(); +} diff --git a/templates/webpages/requirement_spec/show.html b/templates/webpages/requirement_spec/show.html index 5c73a51d3..8df8c00ff 100644 --- a/templates/webpages/requirement_spec/show.html +++ b/templates/webpages/requirement_spec/show.html @@ -41,20 +41,20 @@ diff --git a/templates/webpages/requirement_spec_text_block/_form.html b/templates/webpages/requirement_spec_text_block/_form.html new file mode 100644 index 000000000..1fde6e57a --- /dev/null +++ b/templates/webpages/requirement_spec_text_block/_form.html @@ -0,0 +1,76 @@ +[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% SET style="width: 500px" %] +[% DEFAULT id_base = 'edit_text_block_' _ SELF.text_block.id %] +
+ [% 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) %] + + + + + + + + [%- IF PREDEFINED_TEXTS.size %] + + + + + [%- END %] + + + + + +
[%- LxERP.t8("Title") %]:[% L.input_tag(id_base _ '.title', SELF.text_block.title, style = style) %]
[%- LxERP.t8("Pre-defined text block") %]: + [%- L.select_tag(id_base _ '_predefined_text_block', PREDEFINED_TEXTS, title_key='description', style=style) %] + [%- LxERP.t8("Insert") %] +
[%- LxERP.t8("Description") %]:[% L.textarea_tag(id_base _ '.text', SELF.text_block.text, style = style, rows = 10) %]
+ +

+ [% L.button_tag('submit_edit_text_block_form("' _ id_base _ '")', LxERP.t8('Save')) %] + [%- LxERP.t8("Cancel") %] +

+ +[%- IF PREDEFINED_TEXTS.size %] + +[%- END %] +
diff --git a/templates/webpages/requirement_spec_text_block/_text_block.html b/templates/webpages/requirement_spec_text_block/_text_block.html index ae371f378..6028289bb 100644 --- a/templates/webpages/requirement_spec_text_block/_text_block.html +++ b/templates/webpages/requirement_spec_text_block/_text_block.html @@ -1,14 +1,14 @@ [%- USE HTML -%][%- USE L -%][%- USE LxERP -%] -
-

[%- HTML.escape(text_block.title) %]

+
+

[% IF !text_block.title %][%- LxERP.t8("No title yet") %][% END %][%- HTML.escape(text_block.title) %]

- [% IF !text_block.description %] -
- [%- LxERP.t8("No description has been entered yet.") %] + [% IF !text_block.text %] +
+ [%- LxERP.t8("No text has been entered yet.") %]
[% ELSE %] -
- [% L.simple_format(text_block.description) %] +
+ [% L.simple_format(text_block.text) %]
[% END %]
diff --git a/templates/webpages/requirement_spec_text_block/ajax_list.html b/templates/webpages/requirement_spec_text_block/ajax_list.html index dacf15456..73e1ab3c7 100644 --- a/templates/webpages/requirement_spec_text_block/ajax_list.html +++ b/templates/webpages/requirement_spec_text_block/ajax_list.html @@ -1,14 +1,23 @@ -[%- USE LxERP -%][% nownow %] -

- [%- IF output_position == 0 %][%- LxERP.t8("Text blocks front") %][%- ELSE %][%- LxERP.t8("Text blocks back") %][%- END %] -

+[%- USE LxERP -%][%- USE L -%] - +
+ [% L.hidden_tag('text_block_output_position', output_position) %] +

+ [%- IF output_position == 0 %][%- LxERP.t8("Text blocks front") %][%- ELSE %][%- LxERP.t8("Text blocks back") %][%- END %] +

+ + -
- [%- FOREACH text_block = TEXT_BLOCKS %] - [%- INCLUDE 'requirement_spec_text_block/_text_block.html' %] - [%- END %] +
+ [%- FOREACH text_block = TEXT_BLOCKS %] + [%- INCLUDE 'requirement_spec_text_block/_text_block.html' %] + [%- END %] +
+ +