use parent qw(SL::Controller::Base);
use SL::ClientJS;
+use SL::DB::Part;
use SL::DB::RequirementSpec;
use SL::DB::RequirementSpecOrder;
use SL::Helper::Flash;
use Rose::Object::MakeMethods::Generic
(
- 'scalar --get_set_init' => [ qw(requirement_spec js) ],
+ 'scalar --get_set_init' => [ qw(requirement_spec js all_parts) ],
);
__PACKAGE__->run_before('setup');
sub action_list {
my ($self) = @_;
- $::lxdebug->dump(0, "hmm", $self->requirement_spec->sections_sorted);
$self->render('requirement_spec_order/list', { layout => 0 });
}
+sub action_edit_assignment {
+ my ($self) = @_;
+
+ my $html = $self->render('requirement_spec_order/edit_assignment', { output => 0 }, make_part_title => sub { $_[0]->partnumber . ' ' . $_[0]->description });
+ $self->js->html('#ui-tabs-4', $html)
+ ->render($self);
+}
+
+sub action_save_assignment {
+ my ($self) = @_;
+ my $sections = $::form->{sections} || [];
+ SL::DB::RequirementSpecItem->new(id => $_->{id})->load->update_attributes(order_part_id => ($_->{order_part_id} || undef)) for @{ $sections };
+
+ my $html = $self->render('requirement_spec_order/list', { output => 0 });
+ $self->js->html('#ui-tabs-4', $html)
+ ->render($self);
+}
+
+sub action_cancel {
+ my ($self) = @_;
+
+ my $html = $self->render('requirement_spec_order/list', { output => 0 });
+ $self->js->html('#ui-tabs-4', $html)
+ ->render($self);
+}
+
#
# filters
#
# helpers
#
+sub init_all_parts { SL::DB::Manager::Part->get_all_sorted }
+
1;
return $(clicked_elt).find('>[name=order_id]').val();
};
-ns.standard_quotation_order_ajax_call = function(key, opt, other_data) {
- var data = {
- action: "RequirementSpecOrder/" + key,
- requirement_spec_id: $('#requirement_spec_id').val(),
- id: ns.find_quotation_order_id(opt.$trigger)
- };
+ns.standard_quotation_order_ajax_call = function(key, opt) {
+ if ((key == 'cancel') && !confirm(kivi.t8('Do you really want to cancel?')))
+ return true;
+
+ var data = 'action=RequirementSpecOrder/' + key
+ + '&' + $('#requirement_spec_id').serialize();
+
+ if (key == 'save_assignment')
+ data += '&' + $('#quotations_and_orders_article_assignment_form').serialize();
+ else
+ data += '&id=' + encodeURIComponent(ns.find_quotation_order_id(opt.$trigger));
// console.log("I would normally POST the following now:");
// console.log(data);
- $.post("controller.pl", $.extend(data, other_data || {}), kivi.eval_json_result);
+ $.post("controller.pl", data, kivi.eval_json_result);
return true;
};
return !$('#quotations_and_orders_sections');
};
+ns.assign_order_part_id_to_all = function() {
+ var order_part_id = $('#quoations_and_orders_order_id').val();
+ $('#quotations_and_orders_article_assignment_form SELECT[name="sections[].order_part_id"]').each(function(idx, elt) {
+ $(elt).val(order_part_id);
+ });
+};
+
// -------------------------------------------------------------------------
// ---------------------------- general actions ----------------------------
// -------------------------------------------------------------------------
$.contextMenu({
selector: '.quotations-and-orders-context-menu,.quotations-and-orders-order-context-menu',
items: $.extend({
- heading: { name: kivi.t8('Orders/Quotations actions'), className: 'context-menu-heading' }
- , edit: { name: kivi.t8('Edit article/section assignments'), icon: "edit", callback: ns.standard_quotation_order_ajax_call }
+ heading: { name: kivi.t8('Orders/Quotations actions'), className: 'context-menu-heading' }
+ , edit_assignment: { name: kivi.t8('Edit article/section assignments'), icon: "edit", callback: ns.standard_quotation_order_ajax_call }
, sep1: "---------"
- , new: { name: kivi.t8('Create new qutoation/order'), icon: "add", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands}
- , update: { name: kivi.t8('Update quotation/order'), icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands }
+ , new: { name: kivi.t8('Create new qutoation/order'), icon: "add", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_create_quotation_order_commands }
+ , update: { name: kivi.t8('Update quotation/order'), icon: "update", callback: ns.standard_quotation_order_ajax_call, disabled: ns.disable_edit_quotation_order_commands }
, sep2: "---------"
- , delete: { name: kivi.t8('Delete quotation/order'), icon: "delete", callback: ns.ask_delete_quotation_order, disabled: ns.disable_edit_quotation_order_commands }
+ , delete: { name: kivi.t8('Delete quotation/order'), icon: "delete", callback: ns.ask_delete_quotation_order, disabled: ns.disable_edit_quotation_order_commands }
+ }, general_actions)
+ });
+
+ $.contextMenu({
+ selector: '.quotations-and-orders-edit-assignment-context-menu',
+ items: $.extend({
+ heading: { name: kivi.t8('Edit article/section assignments'), className: 'context-menu-heading' }
+ , save_assignment: { name: kivi.t8('Save'), icon: "edit", callback: ns.standard_quotation_order_ajax_call }
+ , cancel: { name: kivi.t8('Cancel'), icon: "close", callback: ns.standard_quotation_order_ajax_call }
}, general_actions)
});
--- /dev/null
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE P -%]
+<div>
+ [% LxERP.t8("Assign the following article to all sections") %]:
+ [% L.select_tag('quotations_and_orders_dummy', SELF.all_parts, default=INSTANCE_CONF.get_requirement_spec_section_order_part_id, title_sub=\make_part_title, id='quoations_and_orders_order_id') %]
+ [% L.button_tag('kivi.requirement_spec.assign_order_part_id_to_all()', LxERP.t8('Assign article')) %]
+</div>
+
+<form id="quotations_and_orders_article_assignment_form">
+ <table style="width: 100%">
+ <thead>
+ <tr class="listheading">
+ <th>[% LxERP.t8("Number") %]</th>
+ <th>[% LxERP.t8("Title") %]</th>
+ <th>[% LxERP.t8("Description") %]</th>
+ <th>[% LxERP.t8("Article") %]</th>
+ </tr>
+ </thead>
+
+ <tbody>
+ [% FOREACH section = SELF.requirement_spec.sections_sorted %]
+ <tr class="listrow">
+ [% L.hidden_tag("sections[+].id", section.id, no_id=1) %]
+ <td>[% HTML.escape(section.fb_number) %]</td>
+ <td>[% HTML.escape(section.title) %]</td>
+ <td>[% HTML.escape(P.truncate(section.description)) %]</td>
+ <td>[% L.select_tag('sections[].order_part_id', SELF.all_parts, default=section.order_part_id, with_empty=1, title_sub=\make_part_title, no_id=1) %]</td>
+ </tr>
+ [% END %]
+ </tbody>
+ </table>
+</form>