1 /*jshint bitwise:true, indent:2, curly:true, eqeqeq:true, immed:true,
2 latedef:true, newcap:true, noarg:true, regexp:true, undef:true,
3 trailing:true, white:true, strict:false*/
4 /*global XT:true, XM:true, XV:true, _:true, enyo:true */
9 Expected to a have a parameter widget that contains an order and
12 @name XV.TransactionListContainer
13 @extends XV.SearchContainer
15 var transactionListContainer = /** @lends XV.TransactionListContainer# */ {
16 name: "XV.TransactionListContainer",
17 kind: "XV.GridPanels",
23 transactionDate: null,
31 onListItemMenuTap: "showListItemMenu",
32 onParameterChange: "requery",
33 onProcessingChanged: "processingChanged",
34 onSelectionChanged: "selectionChanged"
38 {name: "parameterPanel", kind: "FittableRows", classes: "left",
40 {kind: "onyx.Toolbar", classes: "onyx-menu-toolbar", components: [
41 {kind: "onyx.Button", name: "backButton", content: "_back".loc(), ontap: "close"},
42 {kind: "onyx.MenuDecorator", style: "margin: 0;",
43 onSelect: "actionSelected", components: [
44 {kind: "XV.IconButton", src: "/assets/menu-icon-gear.png",
45 content: "_actions".loc(), name: "actionButton"},
46 {kind: "onyx.Menu", name: "actionMenu"}
49 {kind: "Scroller", name: "parameterScroller"}
51 {name: "listPanel", kind: "FittableRows", components: [
52 // the onyx-menu-toolbar class keeps the popups from being hidden
53 {kind: "onyx.MoreToolbar", name: "contentToolbar",
54 classes: "onyx-menu-toolbar", movedClass: "xv-toolbar-moved", components: [
55 {name: "rightLabel", content: "_search".loc(), classes: "xv-toolbar-label"},
56 {name: "spacer", content: "", fit: true},
57 {kind: "onyx.Button", name: "printButton", showing: false,
58 content: "_print".loc(), onclick: "print"},
59 {kind: "onyx.Button", name: "refreshButton", disabled: false,
60 content: "_refresh".loc(), onclick: "requery"},
61 {kind: "onyx.Button", name: "postButton",
62 disabled: true, classes: "save", showing: false,
63 content: "_post".loc(), onclick: "post"},
64 {name: "listItemMenu", kind: "onyx.Menu", floating: true,
65 onSelect: "listActionSelected", maxHeight: 500}
67 {name: "contentPanels", kind: "Panels", margin: 0, fit: true, draggable: false,
69 {kind: "onyx.Popup", name: "spinnerPopup", centered: true,
70 modal: true, floating: true, scrim: true,
71 onHide: "popupHidden", components: [
72 {kind: "onyx.Spinner"},
73 {name: "spinnerMessage", content: "_processing".loc() + "..."}
77 actionSelected: function (inSender, inEvent) {
78 var action = inEvent.originator.action,
79 method = action.method || action.name;
80 this[method](inSender, inEvent);
85 buildMenu: function () {
86 if (!this.getActions()) {
89 var actionMenu = this.$.actionMenu,
90 actions = this.getActions().slice(0),
94 actionMenu.destroyClientControls();
96 // then add whatever actions are applicable
97 _.each(actions, function (action) {
98 var name = action.name,
99 prerequisite = action.prerequisite,
100 isDisabled = prerequisite ? !that[prerequisite]() : false;
101 actionMenu.createComponent({
104 content: action.label || ("_" + name).loc(),
111 this.$.actionButton.setShowing(actions.length);
113 create: function () {
114 this.inherited(arguments);
115 var disabled = !XT.session.privileges.get("AlterTransactionDates"),
117 this.setList({list: this.getList()});
118 parameterWidget = this.$.parameterWidget;
119 parameterWidget.$.transactionDate.$.input.setDisabled(disabled);
120 if (!this.getActions()) {
124 this.$.contentToolbar.resized();
126 fetch: function (options) {
127 if (!this.init) { return; }
128 options = options ? _.clone(options) : {};
129 var list = this.$.list,
133 if (!list) { return; }
134 query = list.getQuery() || {};
135 parameterWidget = this.$.parameterWidget;
136 parameters = parameterWidget && parameterWidget.getParameters ?
137 parameterWidget.getParameters() : [];
138 options.showMore = _.isBoolean(options.showMore) ?
139 options.showMore : false;
142 if (parameters.length) {
143 query.parameters = parameters;
145 delete query.parameters;
147 list.setQuery(query);
151 Capture order changed and transaction date changed events.
152 Depends on a very specific implementation of parameter widget
153 that includes `order` and `transactionDate` parameters.
155 parameterChanged: function (inSender, inEvent) {
156 var originator = inEvent ? inEvent.originator : false,
157 name = originator ? originator.name : false,
162 if (name === "transactionDate") {
163 value = originator.$.input.getValue();
164 value = XT.date.applyTimezoneOffset(value, true);
165 value = XT.date.toMidnight(value);
166 this.setTransactionDate(value);
169 } else if (name === "order") {
170 value = originator.getParameter().value;
171 this.setModel(value);
173 } else if (name === "shipment") {
178 success: function () {
179 that.selectionChanged();
184 popupHidden: function (inSender, inEvent) {
185 if (!this._popupDone) {
186 inEvent.originator.show();
189 processingChanged: function (inSender, inEvent) {
190 if (inEvent.isProcessing) {
198 Overload: Piggy back on existing handler for `onParameterChanged event`
199 by forwarding this requery to `parameterChanged`.
201 requery: function (inSender, inEvent) {
202 this.parameterChanged(inSender, inEvent);
206 Whenever a user makes a selection, rebuild the menu
207 and set the transaction date on the selected models
208 to match what has been selected here.
210 selectionChanged: function () {
211 this.transactionDateChanged();
215 @param {Object} Options
216 @param {String} [options.list] Class name
218 setList: function (options) {
222 component = this.createComponent({
224 container: this.$.contentPanels,
228 this.$.rightLabel.setContent(component.label);
230 this.createComponent({
231 name: "parameterWidget",
232 classes: "xv-groupbox xv-parameter",
233 showSaveFilter: false,
235 defaultParameters: null,
236 container: this.$.parameterScroller,
237 kind: component.getParameterWidget(),
238 memoizeEnabled: false,
246 spinnerHide: function () {
247 this._popupDone = true;
248 this.$.spinnerPopup.hide();
250 spinnerShow: function () {
251 this._popupDone = false;
252 this.$.spinnerPopup.show();
254 transactionDateChanged: function () {
255 var transDate = this.getTransactionDate(),
256 collection = this.$.list.getValue(),
259 // Update the transaction dates on all models to match
260 // What has been selected
261 for (i = 0; i < collection.length; i++) {
262 collection.at(i).transactionDate = transDate;
267 enyo.mixin(transactionListContainer, XV.ListMenuManagerMixin);
268 enyo.kind(transactionListContainer);