use Time::HiRes ();
use SL::DB::RequirementSpec;
+use SL::DB::RequirementSpecComplexity;
use SL::DB::RequirementSpecItem;
+use SL::DB::RequirementSpecRisk;
use SL::Helper::Flash;
use SL::JSON;
use SL::Locale::String;
use Rose::Object::MakeMethods::Generic
(
- scalar => [ qw(requirement_spec item visible_item visible_section) ],
+ scalar => [ qw(requirement_spec item visible_item visible_section) ],
+ 'scalar --get_set_init' => [ qw(complexities risks) ],
);
# __PACKAGE__->run_before('load_requirement_spec');
-__PACKAGE__->run_before('load_requirement_spec_item', only => [qw(dragged_and_dropped edit_section update_section)]);
+__PACKAGE__->run_before('load_requirement_spec_item', only => [qw(dragged_and_dropped ajax_update ajax_edit)]);
#
# actions
$self->render($js);
}
-sub action_new {
- my ($self) = @_;
-
- eval {
- my $type = ($::form->{item_type} || '') =~ m/^ (?: section | (?: sub-)? function-block ) $/x ? $::form->{item_type} : die "Invalid item_type";
- $self->{item} = SL::DB::RequirementSpecItem->new(requirement_spec_id => $::form->{requirement_spec_id});
- my $section_form = $self->presenter->render("requirement_spec_item/_${type}_form", id => create_random_id(), title => t8('Create a new section'));
-
- $self->render(\to_json({ status => 'ok', html => $section_form }), { type => 'json' });
- 1;
- } or do {
- $self->render(\to_json({ status => 'failed', error => "Exception:\n" . format_exception() }), { type => 'json' });
- }
-}
-
-sub action_create {
- my ($self) = @_;
-
- my $type = ($::form->{item_type} || '') =~ m/^ (?: section | (?: sub-)? function-block ) $/x ? $::form->{item_type} : die "Invalid item_type";
-
- $self->render(\to_json({ status => 'failed', error => 'not good, not good' }), { type => 'json' });
-}
-
sub action_dragged_and_dropped {
my ($self) = @_;
- $::lxdebug->dump(0, "form", $::form);
-
my $dropped_item = SL::DB::RequirementSpecItem->new(id => $::form->{dropped_id})->load || die "No such dropped item";
my $position = $::form->{position} =~ m/^ (?: before | after | last ) $/x ? $::form->{position} : die "Unknown 'position' parameter";
$self->render(\'', { type => 'json' });
}
-sub action_edit_section {
+sub action_ajax_edit {
my ($self, %params) = @_;
- $self->render('requirement_spec_item/_section_form', { layout => 0 });
+
+ $::lxdebug->dump(0, "form", $::form);
+
+ $self->init_visible_section($::form->{current_content_id}, $::form->{current_content_type});
+ $self->item(SL::DB::RequirementSpecItem->new(id => $::form->{id})->load);
+
+ my $js = SL::ClientJS->new;
+
+ die "TODO: edit section" if $self->item->get_type =~ m/section/;
+
+ if (!$self->visible_section || ($self->visible_section->id != $self->item->get_section->id)) {
+ my $html = $self->render('requirement_spec_item/_section', { output => 0 }, requirement_spec_item => $self->item);
+ $js->html('#column-content', $html);
+ }
+
+ if ($self->item->get_type =~ m/function-block/) {
+ my $create_item = sub {
+ [ $_[0]->id, $self->presenter->truncate(join(' ', grep { $_ } ($_[1], $_[0]->fb_number, $_[0]->description))) ]
+ };
+ my @dependencies =
+ map { [ $_->fb_number . ' ' . $_->title,
+ [ map { ( $create_item->($_),
+ map { $create_item->($_, '->') } @{ $_->sorted_children })
+ } @{ $_->sorted_children } ] ]
+ } @{ $self->item->requirement_spec->sections };
+
+ my @selected_dependencies = map { $_->id } @{ $self->item->dependencies };
+
+ my $html = $self->render('requirement_spec_item/_function_block_form', { output => 0 }, DEPENDENCIES => \@dependencies, SELECTED_DEPENDENCIES => \@selected_dependencies);
+ my $id_base = $self->item->get_type . '-' . $self->item->id;
+ my $content_top_id = '#' . $self->item->get_type . '-content-top-' . $self->item->id;
+
+ $js->hide($content_top_id)
+ ->remove("#edit_${id_base}_form")
+ ->insertAfter($html, $content_top_id)
+ ->jstree->select_node('#tree', '#fb-' . $self->item->id)
+ ->focus("#edit_${id_base}_description")
+ ->val('#current_content_type', $self->item->get_type)
+ ->val('#current_content_id', $self->item->id)
+ ->render($self);
+ }
}
-sub action_update_section {
+sub action_ajax_update {
my ($self, %params) = @_;
- $self->item->update_attributes(title => $::form->{title}, description => $::form->{description});
+ my $js = SL::ClientJS->new;
+ my $prefix = $::form->{form_prefix} || 'text_block';
+ my $attributes = $::form->{$prefix} || {};
+
+ foreach (qw(requirement_spec_id parent_id position)) {
+ delete $attributes->{$_} if !defined $attributes->{$_};
+ }
+
+ my @errors = $self->item->assign_attributes(%{ $attributes })->validate;
+ return $js->error(@errors)->render($self) if @errors;
+
+ $self->item->save;
- my $result = {
- id => $self->item->id,
- header_html => $self->render('requirement_spec_item/_section_header', { layout => 0, output => 0 }, requirement_spec_item => $self->item),
- node_name => join(' ', map { $_ || '' } ($self->item->fb_number, $self->item->title)),
- };
- $self->render(\to_json($result), { type => 'json' });
+ my $id_prefix = $self->item->get_type eq 'function-block' ? '' : 'sub-';
+ my $html_top = $self->render('requirement_spec_item/_function_block_content_top', { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix);
+ my $html_bottom = $self->render('requirement_spec_item/_function_block_content_bottom', { output => 0 }, requirement_spec_item => $self->item, id_prefix => $id_prefix);
+ $id_prefix .= 'function-block-content-';
+
+ SL::ClientJS->new
+ ->remove('#' . $prefix . '_form')
+ ->replaceWith('#' . $id_prefix . 'top-' . $self->item->id, $html_top)
+ ->replaceWith('#' . $id_prefix . 'bottom-' . $self->item->id, $html_bottom)
+ ->jstree->rename_node('#tree', '#fb-' . $self->item->id, $::request->presenter->requirement_spec_item_tree_node_title($self->item))
+ ->render($self);
}
#
return $self->visible_section($self->visible_item->get_section);
}
+sub init_complexities {
+ my ($self) = @_;
+
+ return SL::DB::Manager::RequirementSpecComplexity->get_all_sorted;
+}
+
+sub init_risks {
+ my ($self) = @_;
+
+ return SL::DB::Manager::RequirementSpecRisk->get_all_sorted;
+}
+
1;
1;
}
+sub validate {
+ my ($self) = @_;
+
+ my @errors;
+ push @errors, t8('The title is missing.') if !$self->parent_id && !$self->title;
+
+ return @errors;
+}
+
sub sorted_children {
my ($self) = @_;
use parent qw(Exporter);
use Exporter qw(import);
-our @EXPORT = qw(requirement_spec_item_jstree_data requirement_spec_item_dependency_list);
+our @EXPORT = qw(requirement_spec_item_tree_node_title requirement_spec_item_jstree_data requirement_spec_item_dependency_list);
use Carp;
+sub requirement_spec_item_tree_node_title {
+ my ($self, $item) = @_;
+
+ return join(' ', map { $_ || '' } ($item->fb_number, $self->truncate($item->parent_id ? $item->description : $item->title, at => 30), '<' . $item->id . '>'));
+}
+
sub requirement_spec_item_jstree_data {
my ($self, $item, %params) = @_;
my $type = !$item->parent_id ? 'section' : 'function-block';
return {
- data => join(' ', map { $_ || '' } ($item->fb_number, $item->title, '<' . $item->id . '>')),
+ data => $self->requirement_spec_item_tree_node_title($item),
metadata => { id => $item->id, type => $type },
attr => { id => "fb-" . $item->id, href => $params{href} || '#', class => $type . '-context-menu' },
children => \@children,
color: #fff;
background: #ccc;
}
+
+.function-block-form {
+ background: rgb(235, 235, 235);
+ border: 1px solid rgb(0, 100, 0);
+}
+
+.function-block-form > div {
+ padding: 5px;
+}
function standard_item_ajax_call(key, opt, other_data) {
var data = {
- action: "RequirementSpecTextBlock/ajax_" + key,
+ action: "RequirementSpecItem/ajax_" + key,
requirement_spec_id: $('#requirement_spec_id').val(),
id: find_item_id(opt.$trigger),
current_content_type: $('#current_content_type').val(),
current_content_id: $('#current_content_id').val()
};
- console.log("I would normally POST the following now:");
- console.log(data);
- // $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result);
+ // console.log("I would normally POST the following now:");
+ // console.log(data);
+ $.post("controller.pl", $.extend(data, other_data || {}), eval_json_result);
return true;
}
function disable_edit_item_commands(key, opt) {
- return false; // find_item_id(opt.$trigger) == undefined;
+ return find_item_id(opt.$trigger) == undefined;
+}
+
+function submit_edit_item_form(id_base) {
+ var id = $('#' + id_base + '_id').val();
+ var url = "controller.pl?" + $('#' + id_base + '_form').serialize();
+ var data = {
+ action: 'RequirementSpecItem/ajax_' + (id ? 'update' : 'create'),
+ id: id,
+ form_prefix: id_base
+ };
+ $.post(url, data, eval_json_result);
+ return true;
+}
+
+function cancel_edit_item_form(form_id_base, hidden_id_base) {
+ var id = $('#' + form_id_base + '_id').val();
+ $('#' + form_id_base + '_form').remove();
+ if (id)
+ $('#' + hidden_id_base + '-' + id).show();
}
'Description (translation for #1)' => 'Beschreibung (Übersetzung für #1)',
'Description missing!' => 'Beschreibung fehlt.',
'Description must not be empty!' => 'Beschreibung darf nicht leer sein',
+ 'Description of #1' => 'Beschreibung von #1',
'Destination BIC' => 'Ziel-BIC',
'Destination IBAN' => 'Ziel-IBAN',
'Destination bin' => 'Ziellagerplatz',
'Edit requirement spec status' => 'Pflichtenheftstatus bearbeiten',
'Edit requirement spec type' => 'Pflichtenhefttypen bearbeiten',
'Edit risk level' => 'Risikograd bearbeiten',
- 'Edit section #1' => 'Abschnitt #1 bearbeiten',
'Edit templates' => 'Vorlagen bearbeiten',
'Edit text block' => 'Textblock bearbeiten',
'Edit text block \'#1\'' => 'Textblock \'#1\' bearbeiten',
'Edit units' => 'Einheiten bearbeiten',
'Edit user signature' => 'Benutzersignatur bearbeiten',
'Editable' => 'Bearbeitbar',
- 'Effort' => 'Aufwand',
'Either there are no open invoices, or you have already initiated bank transfers with the open amounts for those that are still open.' => 'Entweder gibt es keine offenen Rechnungen, oder es wurden bereits Überweisungen über die offenen Beträge aller offenen Rechnungen erstellt.',
'Element disabled' => 'Element deaktiviert',
'Employee' => 'Bearbeiter',
'No requirement spec statuses has been created yet.' => 'Es wurden noch keine Pflichtenheftstatus angelegt.',
'No requirement spec type has been created yet.' => 'Es wurden noch keine Pflichtenhefttypen angelegt.',
'No risks level has been created yet.' => 'Es wurden noch keine Risikograde angelegt.',
- 'No sections have been created so far.' => '',
+ 'No sections have been created so far.' => 'Bisher wurden noch keine Abschnitte angelegt.',
'No shipto selected to delete' => 'Keine Lieferadresse zum Löschen ausgewählt',
'No summary account' => 'Kein Sammelkonto',
'No text blocks have been created for this position.' => 'Für diese Position wurden noch keine Textblöcke angelegt.',
'Three Options:' => 'Drei Optionen:',
'Time Format' => 'Uhrzeitformat',
'Time Tracking' => 'Zeiterfassung',
+ 'Time estimate' => 'Zeitschätzung',
'Time period for the analysis:' => 'Analysezeitraum:',
'Timestamp' => 'Uhrzeit',
'Title' => 'Titel',
<script type="text/javascript">
<!--
- var tree_data = [
- { data: [% JSON.json(LxERP.t8("Text blocks front")) %],
- metadata: { type: "text-blocks-front" },
- attr: { id: "tb-front", class: "text-block-context-menu" },
- children: [
+$(function() {
+ var tree_data = [
+ { data: [% JSON.json(LxERP.t8("Text blocks 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) %]
[% 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", class: "section-context-menu" },
- children: [
+ ]},
+ { data: [% JSON.json(LxERP.t8("Sections")) %],
+ metadata: { type: "sections" },
+ attr: { id: "sections", class: "section-context-menu" },
+ 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: "text-blocks-back" },
- attr: { id: "tb-back", class: "text-block-context-menu" },
- children: [
+ { data: [% JSON.json(LxERP.t8("Text blocks 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) %]
[% 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"
+ ]}];
+
+ $('#tree').jstree({
+ core: {
+ animation: 0,
+ initially_open: [ "tb-front", "tb-back", "sections"
[%- FOREACH section = SELF.requirement_spec.sections -%]
- , "fb-[% section.id %]"
+ , "fb-[% section.id %]"
[%- FOREACH function_block = section.children -%]
- , "fb-[% function_block.id -%]"
+ , "fb-[% function_block.id -%]"
[%- END -%]
[%- END -%]
- ]
- },
- json_data: {
- data: tree_data
- },
- crrm: {
- move: {
- check_move: requirement_spec_tree_check_move,
- open_move: true
- }
- },
- themes: {
- theme: "requirement-spec"
- },
- plugins: [ "themes", "json_data", "ui", "crrm", "dnd" ]
- })
- .bind("move_node.jstree", requirement_spec_tree_node_moved)
- .bind("click.jstree", requirement_spec_tree_node_clicked);
-[%- IF SELF.requirement_spec_item -%]
- $.jstree._reference("#tree").select_node('fb-[% SELF.requirement_spec_item.id %]', true);
-[%- END -%]
- });
+ ]},
+ json_data: {
+ data: tree_data
+ },
+ crrm: {
+ move: {
+ check_move: requirement_spec_tree_check_move,
+ open_move: true
+ }
+ },
+ themes: {
+ theme: "requirement-spec"
+ },
+ plugins: [ "themes", "json_data", "ui", "crrm", "dnd" ]
+ })
+ .bind("move_node.jstree", requirement_spec_tree_node_moved)
+ .bind("click.jstree", requirement_spec_tree_node_clicked);
+[% IF SELF.requirement_spec_item %]
+ $.jstree._reference("#tree").select_node('#fb-[% SELF.requirement_spec_item.id %]', true);
+[% END %]
+});
function ask_delete_text_block(key, opt) {
if (confirm("[% LxERP.t8("Are you sure?") %]"))
selector: '.section-context-menu',
items: {
add_section: { name: "[% LxERP.t8('Add section') %]", icon: "add", callback: standard_item_ajax_call },
- add_function_block: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_text_block_ajax_call },
+ add_function_block: { name: "[% LxERP.t8('Add function block') %]", icon: "add", callback: standard_text_block_ajax_call, disabled: disable_edit_item_commands },
sep1: "---------",
edit: { name: "[% LxERP.t8('Edit') %]", icon: "edit", callback: standard_item_ajax_call, disabled: disable_edit_item_commands },
delete: { name: "[% LxERP.t8('Delete') %]", icon: "delete", callback: ask_delete_item, disabled: disable_edit_item_commands },
<div class="sub-function-block-header" id="sub-function-block_header_[%- requirement_spec_item.id -%]">
[%- LxERP.t8("Sub function blocks") -%]
</div>
- [%- FOREACH sub_function_block = requirement_spec_item.children -%]
+ [%- FOREACH sub_function_block = requirement_spec_item.sorted_children -%]
[%- INCLUDE 'requirement_spec_item/_sub_function_block.html' requirement_spec_item=sub_function_block -%]
[%- END -%]
</div>
[%- USE LxERP -%][%- USE P -%]<div id="[% id_prefix %]function-block-content-bottom-[% requirement_spec_item.id %]" class="smaller" style="text-align:right">
[%- IF requirement_spec_item.dependencies.size -%]
<span class="gray">
- [%- LxERP.t8("Dependencies") -%]: [%- P.requirement_spec_item_dependency_list(requirement_spec_item.dependencies) -%]
+ [%- LxERP.t8("Dependencies") -%]: [%- P.requirement_spec_item_dependency_list(requirement_spec_item) -%]
</span><br>
[%- END -%]
<span class="gray">
- [%- LxERP.t8("Complexity") -%]: [%- requirement_spec_item.requirement_spec_complexity.description IF requirement_spec_item.requirement_spec_complexity -%]
+ [%- LxERP.t8("Complexity") -%]: [%- requirement_spec_item.complexity.description -%]
|
- [%- LxERP.t8("Risk") -%]: [%- requirement_spec_item.requirement_spec_risk.description IF requirement_spec_item.requirement_spec_risk -%]
+ [%- LxERP.t8("Risk") -%]: [%- requirement_spec_item.risk.description -%]
|
- [%- LxERP.t8("Effort") -%]: [%#- render :partial => 'requirement_spec_items/time_estimation_item', :locals => { :item => requirement_spec_item } -%]
+ [%- LxERP.t8("Time estimate") -%]: TODO: Zeitabschätzung
</span>
</div>
--- /dev/null
+[%- USE LxERP -%][%- USE L -%][%- USE HTML -%][%- USE JavaScript -%][% SET style="width: 500px" %]
+[% DEFAULT id_base = 'edit_function_block_' _ SELF.item.id %]
+<form method="post" id="[% id_base %]_form" class="function-block-form">
+ [% L.hidden_tag(id_base _ '_id', SELF.item.id) %]
+ [% L.hidden_tag(id_base _ '.requirement_spec_id', SELF.item.requirement_spec_id) %]
+ [% L.hidden_tag(id_base _ '.parent_id', SELF.item.parent_id) %]
+ [% IF insert_after %]
+ [% L.hidden_tag(id_base _ '.insert_after', insert_after) %]
+ [% END %]
+
+ <div>
+ <div style="width: 19%; float: right;">
+ [%- LxERP.t8("Dependencies") %]:<br>
+ [%- L.select_tag(id_base _ '.dependencies[]', DEPENDENCIES, default=SELECTED_DEPENDENCIES, with_optgroups=1, multiple=1, size=8, style="width: 100%") %]
+ </div>
+
+ <div style="width: 19%; float: right; margin-right: 5px">
+ [%- LxERP.t8("Complexity") %]:<br>
+ [%- L.select_tag(id_base _ '.complexity_id', SELF.complexities, title_key='description', default=SELF.item.complexity_id, style="width: 100%") %]<br>
+
+ [%- LxERP.t8("Risk") %]:<br>
+ [%- L.select_tag(id_base _ '.risk_id', SELF.risks, title_key='description', default=SELF.item.risk_id, style="width: 100%") %]<br>
+
+[%- IF !SELF.item.children.size %]
+ [%- LxERP.t8("Time estimate") %]:<br>
+ TODO: time estimate input
+[%- END %]
+ </div>
+
+ <div style="width: 59%">
+ [% LxERP.t8("Description of #1", SELF.item.fb_number) %]:<br>
+ [% L.textarea_tag(id_base _ '.description', SELF.item.description, id=id_base _ '_description', rows=8, style="width: 100%") %]
+ </div>
+ </div>
+
+ <p>
+ [% L.button_tag('submit_edit_item_form("' _ id_base _ '")', LxERP.t8('Save')) %]
+ <a href="#" onclick="cancel_edit_item_form('[% id_base %]', '[% SELF.item.get_type %]-content-top')">[%- LxERP.t8("Cancel") %]</a>
+ </p>
+</form>
</div>
<div id="section-list" class="section">
- [%- FOREACH function_block = requirement_spec_item.children -%]
+ [%- FOREACH function_block = requirement_spec_item.sorted_children -%]
[%- INCLUDE 'requirement_spec_item/_function_block.html' requirement_spec_item=function_block -%]
[%- END -%]
</div>