1 /*jshint node:true, indent:2, curly:true, eqeqeq:true, immed:true, latedef:true, newcap:true, noarg:true,
2 regexp:true, undef:true, trailing:true, white:true, strict:false */
3 /*global XT:true, XV:true, XM:true, Backbone:true, window:true, enyo:true, _:true */
7 // ..........................................................
12 name: "XV.AccountWidget",
13 kind: "XV.RelationWidget",
14 collection: "XM.AccountRelationCollection",
15 list: "XV.AccountList"
18 // ..........................................................
23 name: "XV.ContactWidget",
24 kind: "XV.RelationWidget",
25 label: "_contact".loc(),
26 collection: "XM.ContactRelationCollection",
27 list: "XV.ContactList",
29 nameAttribute: "jobTitle",
30 descripAttribute: "phone",
31 classes: "xv-relationwidget",
36 {kind: "FittableColumns", components: [
37 {name: "label", content: "", fit: true, classes: "xv-flexible-label"},
38 {kind: "onyx.InputDecorator", name: "decorator",
39 classes: "xv-input-decorator", components: [
40 {name: "input", kind: "onyx.Input", classes: "xv-subinput",
41 onkeyup: "keyUp", onkeydown: "keyDown", onblur: "receiveBlur",
42 onfocus: "receiveFocus"
44 {kind: "onyx.MenuDecorator", onSelect: "itemSelected", components: [
45 {kind: "onyx.IconButton", classes: "icon-folder-open-alt"},
46 {name: "popupMenu", floating: true, kind: "onyx.Menu",
48 {kind: "XV.MenuItem", name: "searchItem", content: "_search".loc()},
49 {kind: "XV.MenuItem", name: "openItem", content: "_open".loc(),
51 {kind: "XV.MenuItem", name: "newItem", content: "_new".loc(),
55 {name: "completer", kind: "XV.Completer", onSelect: "itemSelected"}
58 {kind: "FittableColumns", components: [
59 {name: "labels", classes: "xv-relationwidget-column left",
61 {name: "jobTitleLabel", content: "_jobTitle".loc() + ":",
62 classes: "xv-relationwidget-description label",
64 {name: "phoneLabel", content: "_phone".loc() + ":",
65 classes: "xv-relationwidget-description label",
67 {name: "alternateLabel", content: "_alternate".loc() + ":",
68 classes: "xv-relationwidget-description label",
70 {name: "faxLabel", content: "_fax".loc() + ":",
71 classes: "xv-relationwidget-description label",
73 {name: "primaryEmailLabel", content: "_email".loc() + ":",
74 classes: "xv-relationwidget-description label",
76 {name: "webAddressLabel", content: "_web".loc() + ":",
77 classes: "xv-relationwidget-description label",
79 {name: "addressLabel", content: "_address".loc() + ":",
80 classes: "xv-relationwidget-description label",
83 {name: "data", fit: true, components: [
84 {name: "name", classes: "xv-relationwidget-description hasLabel"},
85 {name: "description", ontap: "callPhone",
86 classes: "xv-relationwidget-description hasLabel hyperlink"},
87 {name: "alternate", classes: "xv-relationwidget-description hasLabel"},
88 {name: "fax", classes: "xv-relationwidget-description hasLabel"},
89 {name: "primaryEmail", ontap: "sendMail",
90 classes: "xv-relationwidget-description hasLabel hyperlink"},
91 {name: "webAddress", ontap: "openWindow",
92 classes: "xv-relationwidget-description hasLabel hyperlink"},
93 {name: "address", classes: "xv-relationwidget-description hasLabel",
98 disabledChanged: function () {
99 this.inherited(arguments);
100 var disabled = this.getDisabled();
102 this.$.jobTitle.addRemoveClass("disabled", disabled);
103 this.$.phone.addRemoveClass("disabled", disabled);
104 this.$.alternate.addRemoveClass("disabled", disabled);
105 this.$.fax.addRemoveClass("disabled", disabled);
106 this.$.primaryEmail.addRemoveClass("disabled", disabled);
107 this.$.webAddress.addRemoveClass("disabled", disabled);
110 setValue: function (value, options) {
111 this.inherited(arguments);
112 if (value && !value.get) {
113 // the value of the widget is still being fetched asyncronously.
114 // when the value is fetched, this function will be run again,
115 // so for now we can just stop here.
118 var jobTitle = value ? value.get("jobTitle") : "",
119 phone = value ? value.get("phone") : "",
120 alternate = value ? value.get("alternate") : "",
121 fax = value ? value.get("fax") : "",
122 primaryEmail = value ? value.get("primaryEmail") : "",
123 webAddress = value ? value.get("webAddress") : "",
124 address = value ? XM.Address.format(value.get("address")) : "",
125 showAddress = this.getShowAddress();
126 this.$.jobTitleLabel.setShowing(jobTitle);
127 this.$.phoneLabel.setShowing(phone);
128 this.$.alternate.setShowing(alternate);
129 this.$.alternate.setContent(alternate);
130 this.$.alternateLabel.setShowing(alternate);
131 this.$.fax.setShowing(fax);
132 this.$.fax.setContent(fax);
133 this.$.faxLabel.setShowing(fax);
134 this.$.primaryEmail.setShowing(primaryEmail);
135 this.$.primaryEmail.setContent(primaryEmail);
136 this.$.primaryEmailLabel.setShowing(primaryEmail);
137 this.$.webAddress.setShowing(webAddress);
138 this.$.webAddress.setContent(webAddress);
139 this.$.webAddressLabel.setShowing(webAddress);
140 this.$.address.setShowing(address && showAddress);
141 this.$.addressLabel.setShowing(address && showAddress);
142 if (showAddress) { this.$.address.setContent(address); }
144 openWindow: function () {
145 var address = this.value ? this.value.get("webAddress") : null;
146 if (address) { window.open("http://" + address); }
149 callPhone: function () {
150 var phoneNumber = this.value ? this.value.get("phone") : null,
153 win = window.open("tel://" + phoneNumber);
158 sendMail: function () {
159 var email = this.value ? this.value.get("primaryEmail") : null,
162 win = window.open("mailto:" + email);
169 // ..........................................................
174 name: "XV.CustomerWidget",
175 kind: "XV.RelationWidget",
176 collection: "XM.CustomerRelationCollection",
177 list: "XV.CustomerList"
181 name: "XV.BillingCustomerWidget",
182 kind: "XV.RelationWidget",
183 collection: "XM.BillingCustomerCollection",
184 query: { parameters: [{attribute: "isActive", value: true}]},
185 list: "XV.CustomerList"
189 name: "XV.SalesCustomerWidget",
190 kind: "XV.RelationWidget",
191 collection: "XM.SalesCustomerCollection",
192 list: "XV.CustomerList"
195 // ..........................................................
199 name: "XV.CustomerGroupWidget",
200 kind: "XV.RelationWidget",
201 collection: "XM.CustomerGroupCollection",
202 keyAttribute: "name",
203 list: "XV.CustomerGroupList"
206 // ..........................................................
211 name: "XV.CustomerProspectWidget",
212 kind: "XV.RelationWidget",
213 collection: "XM.CustomerProspectRelationCollection",
214 list: "XV.CustomerProspectList",
215 create: function () {
216 var ret = this.inherited(arguments);
217 this.createComponent({
219 name: "customerOrProspectPopup",
224 onShow: "popupShown",
225 onHide: "popupHidden",
227 {content: "_customerOrProspect".loc()},
229 {kind: "onyx.Button", name: "customerButton", content: "_customer".loc(), ontap: "popupTapped",
230 classes: "onyx-blue xv-popup-button"},
231 {kind: "onyx.Button", name: "prospectButton", content: "_prospect".loc(), ontap: "popupTapped",
232 classes: "onyx-blue xv-popup-button"}
235 this.$.newItem.setDisabled(false);
240 this overrides the menuItemSelected function of RelationWidget to
241 account for the different types of models presented by the widget.
243 menuItemSelected: function (inSender, inEvent) {
245 menuItem = inEvent.originator,
246 list = this.getList(),
247 model = this.getValue(),
248 K, status, id, workspace,
251 switch (menuItem.name)
254 callback = function (value) {
255 that.setValue(value);
259 searchText: this.$.input.getValue(),
264 K = model.getClass();
265 status = model.get("status");
266 id = model ? model.id : null;
267 workspace = status === K.PROSPECT_STATUS ? "XV.ProspectWorkspace" : "XV.CustomerWorkspace";
270 workspace: workspace,
276 this.$.customerOrProspectPopup.show();
279 popupTapped: function (inSender, inEvent) {
281 callback = function (model) {
282 if (!model) { return; }
283 var Model = that._collection.model,
287 options.success = function () {
288 that.setValue(value);
290 attrs[Model.prototype.idAttribute] = model.id;
291 value = Model.findOrCreate(attrs);
292 value.fetch(options);
295 this.$.customerOrProspectPopup.hide();
298 workspace: inEvent.originator.name === "customerButton" ?
299 "XV.CustomerWorkspace" : "XV.ProspectWorkspace",
305 // ..........................................................
310 name: "XV.CustomerShiptoWidget",
311 kind: "XV.RelationWidget",
312 collection: "XM.CustomerShiptoRelationCollection",
313 list: "XV.CustomerShiptoList"
316 // ..........................................................
321 name: "XV.DepartmentWidget",
322 kind: "XV.RelationWidget",
323 collection: "XM.DepartmentCollection",
324 list: "XV.DepartmentList"
327 // ..........................................................
332 name: "XV.EmployeeWidget",
333 kind: "XV.RelationWidget",
334 collection: "XM.EmployeeRelationCollection",
335 list: "XV.EmployeeList",
339 // ..........................................................
344 name: "XV.ExpenseCategoryWidget",
345 kind: "XV.RelationWidget",
346 collection: "XM.ExpenseCategoryCollection",
347 list: "XV.ExpenseCategoryList",
351 // ..........................................................
356 name: "XV.IncidentWidget",
357 kind: "XV.RelationWidget",
358 collection: "XM.IncidentRelationCollection",
359 list: "XV.IncidentList",
360 nameAttribute: "description"
363 // ..........................................................
368 name: "XV.ItemWidget",
369 kind: "XV.RelationWidget",
370 collection: "XM.ItemRelationCollection",
372 nameAttribute: "description1",
373 descripAttribute: "description2"
376 // ..........................................................
381 name: "XV.LedgerAccountWidget",
382 kind: "XV.RelationWidget",
383 collection: "XM.LedgerAccountRelationCollection",
384 list: "XV.LedgerAccountList",
385 keyAttribute: "name",
386 nameAttribute: "description"
389 // ..........................................................
394 name: "XV.OpportunityWidget",
395 kind: "XV.RelationWidget",
396 collection: "XM.OpportunityRelationCollection",
397 keyAttribute: "name",
398 list: "XV.OpportunityList"
401 // ..........................................................
406 name: "XV.ProjectWidget",
407 kind: "XV.RelationWidget",
408 collection: "XM.ProjectRelationCollection",
409 list: "XV.ProjectList",
410 create: function () {
411 this.inherited(arguments);
412 this.setShowing(XT.session.settings.get("UseProjects"));
414 setShowing: function (showing) {
415 if (!showing || showing && XT.session.settings.get("UseProjects")) {
416 this.inherited(arguments);
421 // ..........................................................
426 name: "XV.PurchaseOrderWidget",
427 kind: "XV.RelationWidget",
428 collection: "XM.PurchaseOrderRelationCollection",
429 keyAttribute: "number",
430 list: "XV.PurchaseOrderList"
433 // ..........................................................
438 name: "XV.SalesOrderWidget",
439 kind: "XV.RelationWidget",
440 collection: "XM.SalesOrderRelationCollection",
441 keyAttribute: "number",
442 list: "XV.SalesOrderList"
445 // ..........................................................
450 name: "XV.ShiftWidget",
451 kind: "XV.RelationWidget",
452 collection: "XM.ShiftCollection",
456 // ..........................................................
461 name: "XV.UserAccountWidget",
462 classes: "xv-useraccount-widget",
463 kind: "XV.RelationWidget",
464 collection: "XM.UserAccountRelationCollection",
465 list: "XV.UserAccountList",
466 keyAttribute: "username",
467 nameAttribute: "properName"
470 // ..........................................................
475 name: "XV.VendorWidget",
476 kind: "XV.RelationWidget",
477 collection: "XM.VendorRelationCollection",
478 keyAttribute: "number",
479 list: "XV.VendorList"