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(),
27 nameAttribute: "jobTitle",
28 descripAttribute: "phone",
29 collection: "XM.ContactRelationCollection",
30 list: "XV.ContactList"
34 descriptionComponents: [
35 {name: "jobTitleRow", controlClasses: "enyo-inline", showing: false, components: [
36 {classes: 'xv-description', name: "name"}
38 {name: "phoneRow", controlClasses: "enyo-inline", showing: false, components: [
39 {classes: "xv-description hyperlink", target: '_blank', name: "description"}
41 {name: "alternateRow", controlClasses: "enyo-inline", showing: false, components: [
42 {classes: "xv-description hyperlink", target: "_blank", name: "alternate"}
44 {name: "faxRow", controlClasses: "enyo-inline", showing: false, components: [
45 {classes: "xv-description hyperlink", target: "_blank", name: "fax"}
47 {name: "emailRow", controlClasses: "enyo-inline", showing: false, components: [
48 {classes: 'xv-description hyperlink', target: "_blank", name: "email"}
50 {name: "webAddressRow", controlClasses: "enyo-inline", showing: false, components: [
51 {classes: 'xv-description hyperlink', target: "_blank", name: "webAddress"}
53 {name: "addressRow", controlClasses: "enyo-inline", showing: false, components: [
54 {classes: "xv-description", name: "address", allowHtml: true}
57 setValue: function (value, options) {
58 this.inherited(arguments);
60 if (value && !value.get) {
61 // the value of the widget is still being fetched asyncronously.
62 // when the value is fetched, this function will be run again,
63 // so for now we can just stop here.
67 var jobTitle = value ? value.get("jobTitle") : "",
68 phone = value ? value.get("phone") : "",
69 alternate = value ? value.get("alternate") : "",
70 fax = value ? value.get("fax") : "",
71 primaryEmail = value ? value.get("primaryEmail") : "",
72 webAddress = value ? value.get("webAddress") : "",
73 address = value ? XM.Address.format(value.get("address")) : "",
74 showAddress = this.getShowAddress();
76 this.$.jobTitleRow.setShowing(!!jobTitle);
77 this.$.name.setContent(jobTitle);
79 this.$.phoneRow.setShowing(!!phone);
80 this.$.description.setContent(phone);
81 this.$.description.setAttribute('href', 'tel://' + phone);
83 this.$.alternateRow.setShowing(!!alternate);
84 this.$.alternate.setContent(alternate);
85 this.$.alternate.setAttribute('href', 'tel://' + alternate);
87 this.$.faxRow.setShowing(!!fax);
88 this.$.fax.setContent(fax);
89 this.$.fax.setAttribute('href', 'tel://' + fax);
91 this.$.emailRow.setShowing(!!primaryEmail);
92 this.$.email.setContent(primaryEmail);
93 this.$.email.setAttribute('href', 'mailto:' + primaryEmail);
95 this.$.webAddressRow.setShowing(!!webAddress);
96 this.$.webAddress.setContent(webAddress);
97 this.$.webAddress.setAttribute('href', '//' + alternate);
99 this.$.addressRow.setShowing(address && showAddress);
100 this.$.address.setContent(address);
102 openWindow: function () {
103 var address = this.value ? this.value.get("webAddress") : null;
104 if (address) { window.open("http://" + address); }
107 callPhone: function () {
108 var phoneNumber = this.value ? this.value.get("phone") : null,
111 win = window.open("tel://" + phoneNumber);
116 sendMail: function () {
117 var email = this.value ? this.value.get("primaryEmail") : null,
120 win = window.open("mailto:" + email);
127 // ..........................................................
132 name: "XV.CustomerWidget",
133 kind: "XV.RelationWidget",
134 collection: "XM.CustomerRelationCollection",
135 list: "XV.CustomerList"
139 name: "XV.BillingCustomerWidget",
140 kind: "XV.RelationWidget",
141 collection: "XM.BillingCustomerCollection",
142 query: { parameters: [{attribute: "isActive", value: true}]},
143 list: "XV.CustomerList"
147 name: "XV.SalesCustomerWidget",
148 kind: "XV.RelationWidget",
149 collection: "XM.SalesCustomerCollection",
150 list: "XV.CustomerList"
153 // ..........................................................
157 name: "XV.CustomerGroupWidget",
158 kind: "XV.RelationWidget",
159 collection: "XM.CustomerGroupCollection",
160 keyAttribute: "name",
161 list: "XV.CustomerGroupList"
164 // ..........................................................
169 name: "XV.CustomerProspectWidget",
170 kind: "XV.RelationWidget",
171 collection: "XM.CustomerProspectRelationCollection",
172 list: "XV.CustomerProspectList",
173 create: function () {
174 var ret = this.inherited(arguments);
175 this.createComponent({
177 name: "customerOrProspectPopup",
182 onShow: "popupShown",
183 onHide: "popupHidden",
185 {content: "_customerOrProspect".loc()},
187 {kind: "onyx.Button", name: "customerButton", content: "_customer".loc(), ontap: "popupTapped",
188 classes: "onyx-blue xv-popup-button"},
189 {kind: "onyx.Button", name: "prospectButton", content: "_prospect".loc(), ontap: "popupTapped",
190 classes: "onyx-blue xv-popup-button"}
193 this.$.newItem.setDisabled(false);
198 this overrides the menuItemSelected function of RelationWidget to
199 account for the different types of models presented by the widget.
201 menuItemSelected: function (inSender, inEvent) {
203 menuItem = inEvent.originator,
204 list = this.getList(),
205 model = this.getValue(),
206 K, status, id, workspace,
209 switch (menuItem.name)
212 callback = function (value) {
213 that.setValue(value);
217 searchText: this.$.input.getValue(),
222 K = model.getClass();
223 status = model.get("status");
224 id = model ? model.id : null;
225 workspace = status === K.PROSPECT_STATUS ? "XV.ProspectWorkspace" : "XV.CustomerWorkspace";
228 workspace: workspace,
234 this.$.customerOrProspectPopup.show();
237 popupTapped: function (inSender, inEvent) {
239 callback = function (model) {
240 if (!model) { return; }
241 var Model = that._collection.model,
245 options.success = function () {
246 that.setValue(value);
248 attrs[Model.prototype.idAttribute] = model.id;
249 value = Model.findOrCreate(attrs);
250 value.fetch(options);
253 this.$.customerOrProspectPopup.hide();
256 workspace: inEvent.originator.name === "customerButton" ?
257 "XV.CustomerWorkspace" : "XV.ProspectWorkspace",
263 // ..........................................................
268 name: "XV.CustomerShiptoWidget",
269 kind: "XV.RelationWidget",
270 collection: "XM.CustomerShiptoRelationCollection",
271 list: "XV.CustomerShiptoList"
274 // ..........................................................
279 name: "XV.DepartmentWidget",
280 kind: "XV.RelationWidget",
281 collection: "XM.DepartmentCollection",
282 list: "XV.DepartmentList"
285 // ..........................................................
290 name: "XV.EmployeeWidget",
291 kind: "XV.RelationWidget",
292 collection: "XM.EmployeeRelationCollection",
293 list: "XV.EmployeeList",
297 // ..........................................................
302 name: "XV.ExpenseCategoryWidget",
303 kind: "XV.RelationWidget",
304 collection: "XM.ExpenseCategoryCollection",
305 list: "XV.ExpenseCategoryList",
309 // ..........................................................
314 name: "XV.IncidentWidget",
315 kind: "XV.RelationWidget",
316 collection: "XM.IncidentRelationCollection",
317 list: "XV.IncidentList",
318 nameAttribute: "description"
321 // ..........................................................
326 name: "XV.ItemWidget",
327 kind: "XV.RelationWidget",
328 collection: "XM.ItemRelationCollection",
330 nameAttribute: "description1",
331 descripAttribute: "description2"
334 // ..........................................................
339 name: "XV.LedgerAccountWidget",
340 kind: "XV.RelationWidget",
341 collection: "XM.LedgerAccountRelationCollection",
342 list: "XV.LedgerAccountList",
343 keyAttribute: "name",
344 nameAttribute: "description"
347 // ..........................................................
352 name: "XV.OpportunityWidget",
353 kind: "XV.RelationWidget",
354 collection: "XM.OpportunityRelationCollection",
355 keyAttribute: "name",
356 list: "XV.OpportunityList"
359 // ..........................................................
364 name: "XV.ProjectWidget",
365 kind: "XV.RelationWidget",
366 collection: "XM.ProjectRelationCollection",
367 list: "XV.ProjectList",
368 create: function () {
369 this.inherited(arguments);
370 this.setShowing(XT.session.settings.get("UseProjects"));
372 setShowing: function (showing) {
373 if (!showing || showing && XT.session.settings.get("UseProjects")) {
374 this.inherited(arguments);
379 // ..........................................................
384 name: "XV.PurchaseOrderWidget",
385 kind: "XV.RelationWidget",
386 collection: "XM.PurchaseOrderRelationCollection",
387 keyAttribute: "number",
388 list: "XV.PurchaseOrderList"
391 // ..........................................................
396 name: "XV.SalesOrderWidget",
397 kind: "XV.RelationWidget",
398 collection: "XM.SalesOrderRelationCollection",
399 keyAttribute: "number",
400 list: "XV.SalesOrderList"
403 // ..........................................................
408 name: "XV.ShiftWidget",
409 kind: "XV.RelationWidget",
410 collection: "XM.ShiftCollection",
414 // ..........................................................
419 name: "XV.UserAccountWidget",
420 classes: "xv-useraccount-widget",
421 kind: "XV.RelationWidget",
422 collection: "XM.UserAccountRelationCollection",
423 list: "XV.UserAccountList",
424 keyAttribute: "username",
425 nameAttribute: "properName"
428 // ..........................................................
433 name: "XV.VendorWidget",
434 kind: "XV.RelationWidget",
435 collection: "XM.VendorRelationCollection",
436 keyAttribute: "number",
437 list: "XV.VendorList"