From c88705d8a32b5f1fabb0d14239fa486ed683a403 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 4 Nov 2014 11:26:28 +0100 Subject: [PATCH] =?utf8?q?Pflichtenhefte:=20vordef=20Textbl=C3=B6cke=20auc?= =?utf8?q?h=20bei=20Abschnitten=20verwenden=20k=C3=B6nnen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/Controller/RequirementSpecItem.pm | 7 +++- .../requirement_spec_item/_section_form.html | 16 ++++++++++ .../requirement_spec_text_block/_form.html | 32 ++----------------- .../_predefined_text_inserter.js | 28 ++++++++++++++++ 4 files changed, 52 insertions(+), 31 deletions(-) create mode 100644 templates/webpages/requirement_spec_text_block/_predefined_text_inserter.js diff --git a/SL/Controller/RequirementSpecItem.pm b/SL/Controller/RequirementSpecItem.pm index 44a260219..c8119be35 100644 --- a/SL/Controller/RequirementSpecItem.pm +++ b/SL/Controller/RequirementSpecItem.pm @@ -14,6 +14,7 @@ use SL::Controller::Helper::RequirementSpec; use SL::DB::RequirementSpec; use SL::DB::RequirementSpecComplexity; use SL::DB::RequirementSpecItem; +use SL::DB::RequirementSpecPredefinedText; use SL::DB::RequirementSpecRisk; use SL::Helper::Flash; use SL::JSON; @@ -22,7 +23,7 @@ use SL::Locale::String; use Rose::Object::MakeMethods::Generic ( scalar => [ qw(item visible_item visible_section clicked_item sections) ], - 'scalar --get_set_init' => [ qw(complexities risks js) ], + 'scalar --get_set_init' => [ qw(complexities risks js predefined_texts) ], ); __PACKAGE__->run_before('check_auth'); @@ -528,6 +529,10 @@ sub init_risks { return SL::DB::Manager::RequirementSpecRisk->get_all_sorted; } +sub init_predefined_texts { + return SL::DB::Manager::RequirementSpecPredefinedText->get_all_sorted(where => [ useable_for_sections => 1 ]); +} + sub init_js { my ($self) = @_; $self->js(SL::ClientJS->new); diff --git a/templates/webpages/requirement_spec_item/_section_form.html b/templates/webpages/requirement_spec_item/_section_form.html index 9f65c9aea..93d75bed8 100644 --- a/templates/webpages/requirement_spec_item/_section_form.html +++ b/templates/webpages/requirement_spec_item/_section_form.html @@ -25,6 +25,14 @@ [% L.input_tag(id_base _ '.title', SELF.item.title, style=style) %]

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

+ [%- LxERP.t8("Pre-defined Texts") %]:
+ [%- L.select_tag(id_base _ '_predefined_text_block', SELF.predefined_texts, title_key='description', style=style) %] + [%- LxERP.t8("Insert") %] +

+ [%- END %] +

[%- LxERP.t8("Description") %]:
[% L.textarea_tag(id_base _ '.description_as_restricted_html', SELF.item.description_as_restricted_html, id=id_base _ '_description', rows=8, cols=80, style=style, class='texteditor') %] @@ -34,4 +42,12 @@ [% L.ajax_submit_tag('controller.pl?action=RequirementSpecItem/ajax_' _ (SELF.item.id ? 'update' : 'create'), '#' _ id_base _ '_form', LxERP.t8('Save')) %] [%- LxERP.t8("Cancel") %]

+ +[%- IF SELF.predefined_texts.size %] + +[%- END %] diff --git a/templates/webpages/requirement_spec_text_block/_form.html b/templates/webpages/requirement_spec_text_block/_form.html index 897647880..545ba19ee 100644 --- a/templates/webpages/requirement_spec_text_block/_form.html +++ b/templates/webpages/requirement_spec_text_block/_form.html @@ -1,4 +1,4 @@ -[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% SET style="width: 500px" %] +[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][% SET style="width: 500px" %] [% DEFAULT id_base = 'edit_text_block_' _ SELF.text_block.id %]

@@ -48,35 +48,7 @@ [%- IF SELF.predefined_texts.size %] [%- END %] diff --git a/templates/webpages/requirement_spec_text_block/_predefined_text_inserter.js b/templates/webpages/requirement_spec_text_block/_predefined_text_inserter.js new file mode 100644 index 000000000..a80084207 --- /dev/null +++ b/templates/webpages/requirement_spec_text_block/_predefined_text_inserter.js @@ -0,0 +1,28 @@ +[% USE JavaScript %] +function insert_selected_predefined_text() { + var data = { +[%- FOREACH pt = SELF.predefined_texts %] + [% HTML.escape(pt.id) %]: { + title: "[% JavaScript.escape(pt.title) %]", + text: "[% JavaScript.escape(pt.text) %]" + }[% UNLESS loop.last %],[% END %] +[% END %] + } + + var id = $('#[% id_base %]_predefined_text_block').val(); + var pt = data[id]; + if (!pt) + return false; + + var title_ctrl = $('#[% id_base %][% title_ctrl_id %]'); + + if ( ((pt.title || '') != '') + && ( ((title_ctrl.val() || '') == '') + || confirm('[%- LxERP.t8("Do you want to overwrite your current title?") %]'))) + title_ctrl.val(pt.title); + + if ((pt.text || '') != '') + $('#[% id_base %][% text_ctrl_id %]').ckeditorGet().insertHtml(pt.text); + + return false; +} -- 2.20.1