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;
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');
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);
[% L.input_tag(id_base _ '.title', SELF.item.title, style=style) %]
</p>
+ [%- IF SELF.predefined_texts.size %]
+ <p>
+ [%- LxERP.t8("Pre-defined Texts") %]:<br>
+ [%- L.select_tag(id_base _ '_predefined_text_block', SELF.predefined_texts, title_key='description', style=style) %]
+ <a href="#" onclick="insert_selected_predefined_text()">[%- LxERP.t8("Insert") %]</a>
+ </p>
+ [%- END %]
+
<p>
[%- LxERP.t8("Description") %]:<br>
[% 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') %]
[% L.ajax_submit_tag('controller.pl?action=RequirementSpecItem/ajax_' _ (SELF.item.id ? 'update' : 'create'), '#' _ id_base _ '_form', LxERP.t8('Save')) %]
<a href="#" onclick="kivi.requirement_spec.cancel_edit_item_form('[% id_base %]', { to_show: '[% hidden %]' })">[%- LxERP.t8("Cancel") %]</a>
</p>
+
+[%- IF SELF.predefined_texts.size %]
+ <script type="text/javascript">
+<!--
+[% INCLUDE 'requirement_spec_text_block/_predefined_text_inserter.js' title_ctrl_id='_title' text_ctrl_id='_description' %]
+-->
+ </script>
+[%- END %]
</form>
-[%- 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 %]
<form method="post" id="[% id_base %]_form">
<h2>
[%- IF SELF.predefined_texts.size %]
<script type="text/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) {
- console.log("insert: case 1; id: " + id);
- return false;
- }
-
- var title_ctrl = $('#[% id_base %]_title');
-
- 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').ckeditorGet().insertHtml(pt.text);
-
- return false;
-}
+[% INCLUDE 'requirement_spec_text_block/_predefined_text_inserter.js' title_ctrl_id='_title' text_ctrl_id='_text' %]
-->
</script>
[%- END %]
--- /dev/null
+[% 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;
+}