);
__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) ]);
$self->render('1;', { type => 'js', inline => 1 });
}
-sub action_tree {
- my ($self) = @_;
- my $r = $self->render('requirement_spec/tree', now => DateTime->now);
-}
-
#
# filters
#
use parent qw(SL::Controller::Base);
+use Time::HiRes ();
+
use SL::ClientJS;
use SL::DB::RequirementSpec;
use SL::DB::RequirementSpecPredefinedText;
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)]);
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 {
->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);
}
->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) = @_;
->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;
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 {
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;
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' },
};
}
#tree-column {
float: left;
width: 25%;
- border-right: 1px solid black;
}
#content-column {
- float: left;
+ float: right;
+ width: 74%;
padding-left: 10px;
}
// 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;
}
// 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;
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(),
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(),
}
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;
}
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;
}
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) {
'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.',
</div>
<div id="column-container">
- <div id="tree-column" style="border-right: 1px solid black">
- <div style="min-height: 32px; height: 32px;">
- <div style="float: left">
- [% L.button_tag("new_section_form()", LxERP.t8("New section"), id="new-section-button") %]
- </div>
- <div id="spinner" class="clearfix" style="float: right; display: none; background:url('js/themes/requirement-spec/throbber.gif') center center no-repeat !important; min-height: 32px; height: 32px; min-width: 32px; width: 32px;"></div>
- </div>
-
+ <div id="tree-column">
<div id="tree"></div>
</div>
<!--
var tree_data = [
{ data: [% JSON.json(LxERP.t8("Text blocks front")) %],
- metadata: { type: "textblocks-front" },
+ metadata: { type: "text-blocks-front" },
attr: { id: "tb-front", class: "text-block-context-menu" },
children: [
[% FOREACH tb = SELF.requirement_spec.text_blocks_for_position(0) %]
},
{ data: [% JSON.json(LxERP.t8("Text blocks back")) %],
- metadata: { type: "textblocks-back" },
+ metadata: { type: "text-blocks-back" },
attr: { id: "tb-back", class: "text-block-context-menu" },
children: [
[% FOREACH tb = SELF.requirement_spec.text_blocks_for_position(1) %]
function ask_delete_text_block(key, opt) {
if (confirm("[% LxERP.t8("Are you sure?") %]"))
- delete_text_block(key, opt);
+ standard_text_block_ajax_call(key, opt);
return true;
}
$.contextMenu({
selector: '.text-block-context-menu',
items: {
- add: { name: "[% LxERP.t8('Add text block') %]", icon: "add", callback: add_text_block },
- edit: { name: "[% LxERP.t8('Edit text block') %]", icon: "edit", callback: edit_text_block, disabled: disable_edit_text_block_commands },
+ add: { name: "[% LxERP.t8('Add text block') %]", icon: "add", callback: standard_text_block_ajax_call },
+ edit: { name: "[% LxERP.t8('Edit text block') %]", icon: "edit", callback: standard_text_block_ajax_call, disabled: disable_edit_text_block_commands },
delete: { name: "[% LxERP.t8('Delete text block') %]", icon: "delete", callback: ask_delete_text_block, disabled: disable_edit_text_block_commands },
sep1: "---------",
copy: { name: "[% LxERP.t8('Copy') %]", icon: "copy", disabled: disable_edit_text_block_commands },
+++ /dev/null
-[%- USE HTML %][%- USE L %][%- USE LxERP %][% USE P %][% USE JSON %]
-
-[%- L.hidden_tag('requirement_spec_id', SELF.requirement_spec.id) -%]
-
-<div id="column-container">
- <div id="tree-column">
- <div style="min-height: 32px; height: 32px;">
- <div style="float: left">
- [% L.button_tag("new_section_form()", LxERP.t8("New section"), id="new-section-button") %]
- </div>
- <div style="clear: both"></div>
- </div>
-
- <div id="tree"></div>
- </div>
-
- <div id="content-column" class="clearfix">
- <p>There's beauty in the breakdown. 0</p>
- <p>There's beauty in the breakdown. 1</p>
- <p>There's beauty in the breakdown. 2</p>
- <p>There's beauty in the breakdown. 3</p>
- <p>There's beauty in the breakdown. 4</p>
- <p>There's beauty in the breakdown. 5</p>
- <p>There's beauty in the breakdown. 6</p>
- <p>There's beauty in the breakdown. 7</p>
- <p>There's beauty in the breakdown. 8</p>
- <p>There's beauty in the breakdown. 9</p>
- <p>There's beauty in the breakdown. 10</p>
- <p>There's beauty in the breakdown. 11</p>
- <p>There's beauty in the breakdown. 12</p>
- <p>There's beauty in the breakdown. 13</p>
- <p>There's beauty in the breakdown. 14</p>
- <p>There's beauty in the breakdown. 15</p>
- <p>There's beauty in the breakdown. 16</p>
- <p>There's beauty in the breakdown. 17</p>
- <p>There's beauty in the breakdown. 18</p>
- <p>There's beauty in the breakdown. 19</p>
- <p>There's beauty in the breakdown. 20</p>
- <p>There's beauty in the breakdown. 21</p>
- <p>There's beauty in the breakdown. 22</p>
- <!-- <p>There's beauty in the breakdown. 23</p> -->
- <!-- <p>There's beauty in the breakdown. 24</p> -->
- <!-- <p>There's beauty in the breakdown. 25</p> -->
- <!-- <p>There's beauty in the breakdown. 26</p> -->
- <!-- <p>There's beauty in the breakdown. 27</p> -->
- <!-- <p>There's beauty in the breakdown. 28</p> -->
- <!-- <p>There's beauty in the breakdown. 29</p> -->
- <!-- <p>There's beauty in the breakdown. 30</p> -->
- <!-- <p>There's beauty in the breakdown. 31</p> -->
- <!-- <p>There's beauty in the breakdown. 32</p> -->
- <!-- <p>There's beauty in the breakdown. 33</p> -->
- <!-- <p>There's beauty in the breakdown. 34</p> -->
- <!-- <p>There's beauty in the breakdown. 35</p> -->
- </div>
-</div>
-
-<script type="text/javascript">
- <!--
- var tree_data = [
- { "data": [% JSON.json(LxERP.t8("Text blocks front")) %],
- "metadata": { "type": "textblocks-front" },
- "attr": { "id": "tb-front" },
- "children": [
-[% FOREACH tb = SELF.requirement_spec.text_blocks_for_position(0) %]
- [% P.requirement_spec_text_block_jstree_data(tb).json %][% IF !loop.last %],[% END %]
-[% END %]
- ]
- },
-
- { "data": [% JSON.json(LxERP.t8("Sections")) %],
- "metadata": { "type": "sections" },
- "attr": { "id": "sections" },
- "children": [
-
-[% FOREACH section = SELF.requirement_spec.sections %]
- [% P.requirement_spec_item_jstree_data(section).json %][% IF !loop.last %],[% END %]
-[% END %]
- ]
- },
-
- { "data": [% JSON.json(LxERP.t8("Text blocks back")) %],
- "metadata": { "type": "textblocks-back" },
- "attr": { "id": "tb-back" },
- "children": [
-[% FOREACH tb = SELF.requirement_spec.text_blocks_for_position(1) %]
- [% P.requirement_spec_text_block_jstree_data(tb).json %][% IF !loop.last %],[% END %]
-[% END %]
- ]
- }
- ];
-
- $(function() {
- $('#tree').jstree({
- "core": {
- "animation": 0,
- "initially_open": [ "tb-front", "tb-back", "sections"
-[%- FOREACH section = SELF.requirement_spec.sections -%]
- , "fb-[% section.id %]"
- [%- FOREACH function_block = section.children -%]
- , "fb-[% function_block.id -%]"
- [%- END -%]
-[%- END -%]
- ]
- },
- "json_data": {
- "data": tree_data
- },
- "crrm": {
- "move": {
- "check_move": check_move,
- "open_move": true
- }
- },
- "themes": {
- "theme": "requirement-spec"
- },
- "plugins": [ "themes", "json_data", "ui", "crrm", "dnd" ]
- })
- .bind("move_node.jstree", node_moved);
- });
- -->
-</script>
[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% SET style="width: 500px" %]
[% DEFAULT id_base = 'edit_text_block_' _ SELF.text_block.id %]
<form method="post" id="[% id_base %]_form">
+ <h2>
+ [%- 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 %]
+ </h2>
+
[% 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) %]
<td>[% L.input_tag(id_base _ '.title', SELF.text_block.title, style = style) %]</td>
</tr>
- [%- IF PREDEFINED_TEXTS.size %]
+ [%- IF SELF.predefined_texts.size %]
<tr>
<th align="right">[%- LxERP.t8("Pre-defined Texts") %]:</th>
<td>
- [%- 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) %]
<a href="#" onclick="insert_selected_predefined_text()">[%- LxERP.t8("Insert") %]</a>
</td>
</tr>
<a href="#" onclick="cancel_edit_text_block_form('[% id_base %]')">[%- LxERP.t8("Cancel") %]</a>
</p>
-[%- IF PREDEFINED_TEXTS.size %]
+[%- IF SELF.predefined_texts.size %]
<script type="text/javascript">
<!--
function insert_selected_predefined_text() {
var data = {
-[%- FOREACH pt = PREDEFINED_TEXTS %]
+[%- FOREACH pt = SELF.predefined_texts %]
[% HTML.escape(pt.id) %]: {
title: "[% JavaScript.escape(pt.title) %]",
text: "[% JavaScript.escape(pt.text) %]"