PageRenderTime 43ms CodeModel.GetById 11ms app.highlight 28ms RepoModel.GetById 1ms app.codeStats 0ms

/enyo-client/application/source/models/static.js

https://github.com/112028/xtuple
JavaScript | 470 lines | 409 code | 29 blank | 32 comment | 22 complexity | 1a9a8b5cfdc60b035caa6ed919f52502 MD5 | raw file
  1/*jshint indent:2, curly:true, eqeqeq:true, immed:true, latedef:true,
  2newcap:true, noarg:true, regexp:true, undef:true, strict:true, trailing:true,
  3white:true*/
  4/*global XM:true, Backbone:true, _:true */
  5
  6(function () {
  7  "use strict";
  8
  9  // These are hard coded collections that may be turned into tables at a later date
 10  var i,
 11    K;
 12
 13  // Account Type
 14  var accountTypeJson = [
 15    { id: "O", name: "_organization".loc() },
 16    { id: "I", name: "_individual".loc() }
 17  ];
 18  XM.AccountTypeModel = Backbone.Model.extend({
 19  });
 20  XM.AccountTypeCollection = Backbone.Collection.extend({
 21    model: XM.AccountTypeModel
 22  });
 23  XM.accountTypes = new XM.AccountTypeCollection();
 24  for (i = 0; i < accountTypeJson.length; i++) {
 25    var accountType = new XM.AccountTypeModel(accountTypeJson[i]);
 26    XM.accountTypes.add(accountType);
 27  }
 28
 29  // Configuration
 30  var configurationJson = [
 31    {
 32      model: "XM.databaseInformation",
 33      name: "_database".loc(),
 34      description: "_databaseInformation".loc(),
 35      workspace: "XV.DatabaseInformationWorkspace"
 36    },
 37    {
 38      model: "XM.system",
 39      name: "_system".loc(),
 40      description: "_systemConfiguration".loc(),
 41      workspace: "XV.SystemConfigurationWorkspace"
 42    }
 43  ];
 44  XM.ConfigurationModel = Backbone.Model.extend({
 45    attributeId: 'model'
 46  });
 47  XM.ConfigurationCollection = Backbone.Collection.extend({
 48    model: XM.AccountTypeModel
 49  });
 50  XM.configurations = new XM.ConfigurationCollection();
 51  _.each(configurationJson, function (config) {
 52    var configuration = new XM.ConfigurationModel(config);
 53    XM.configurations.add(configuration);
 54  });
 55
 56  // Balance Methods
 57  var balanceMethodJson = [
 58    { id: "B", name: "_balanceForward".loc() },
 59    { id: "O", name: "_openItems".loc() }
 60  ];
 61  XM.BalanceMethodModel = Backbone.Model.extend({
 62  });
 63  XM.BalanceMethodCollection = Backbone.Collection.extend({
 64    model: XM.BalanceMethodModel
 65  });
 66  XM.balanceMethods = new XM.BalanceMethodCollection();
 67  for (i = 0; i < balanceMethodJson.length; i++) {
 68    var balanceMethod = new XM.BalanceMethodModel(balanceMethodJson[i]);
 69    XM.balanceMethods.add(balanceMethod);
 70  }
 71
 72  // Credit Card Gateways
 73  XM.CreditCardGatewayModel = Backbone.Model.extend({
 74    getValue: function (key) {
 75      return this.get(key);
 76    }
 77  });
 78  XM.CreditCardGatewayCollection = Backbone.Collection.extend({
 79    model: XM.CreditCardGatewayModel
 80  });
 81  XM.creditCardGateways = new XM.CreditCardGatewayCollection();
 82  // new and better way
 83  _.each([
 84      { id: "Authorize.Net", name: "Authorize.Net" },
 85      { id: "External", name: "External" }
 86    ], function (attrs) {
 87      XM.creditCardGateways.add(new XM.CreditCardGatewayModel(attrs));
 88    }
 89  );
 90
 91  // Credit Card Type
 92  var creditCardTypeJson = [
 93    { id: "A", name: "_amEx".loc() },
 94    { id: "D", name: "_discover".loc() },
 95    { id: "M", name: "_masterCard".loc() },
 96    { id: "V", name: "_visa".loc() }
 97  ];
 98  XM.CreditCardTypeModel = Backbone.Model.extend({
 99  });
100  XM.CreditCardTypeCollection = Backbone.Collection.extend({
101    model: XM.CreditCardTypeModel
102  });
103  XM.creditCardTypes = new XM.CreditCardTypeCollection();
104  for (i = 0; i < creditCardTypeJson.length; i++) {
105    var creditCardType = new XM.CreditCardTypeModel(creditCardTypeJson[i]);
106    XM.creditCardTypes.add(creditCardType);
107  }
108
109  // Credit Status
110  K = XM.Customer;
111  var creditStatusJson = [
112    { id: K.CREDIT_GOOD, name: "_goodStanding".loc() },
113    { id: K.CREDIT_WARN, name: "_creditWarning".loc() },
114    { id: K.CREDIT_HOLD, name: "_creditHolding".loc() }
115  ];
116  XM.CreditStatusModel = Backbone.Model.extend({
117  });
118  XM.CreditStatusCollection = Backbone.Collection.extend({
119    model: XM.CreditStatusModel
120  });
121  XM.creditStatuses = new XM.CreditStatusCollection();
122  for (i = 0; i < creditStatusJson.length; i++) {
123    var creditStatus = new XM.CreditStatusModel(creditStatusJson[i]);
124    XM.creditStatuses.add(creditStatus);
125  }
126
127  // Incident Status (TODO: There is actually already a table for this one...)
128  K = XM.Incident;
129  var incidentStatusJson = [
130    { id: K.NEW, name: "_new".loc() },
131    { id: K.FEEDBACK, name: "_feedback".loc() },
132    { id: K.CONFIRMED, name: "_confirmed".loc() },
133    { id: K.ASSIGNED, name: "_assigned".loc() },
134    { id: K.RESOLVED, name: "_resolved".loc() },
135    { id: K.CLOSED, name: "_closed".loc() }
136  ];
137  XM.IncidentStatusModel = Backbone.Model.extend();
138  XM.IncidentStatusCollection = Backbone.Collection.extend({
139    model: XM.IncidentStatusModel
140  });
141  XM.incidentStatuses = new XM.IncidentStatusCollection();
142  for (i = 0; i < incidentStatusJson.length; i++) {
143    var incidentStatus = new XM.IncidentStatusModel(incidentStatusJson[i]);
144    XM.incidentStatuses.add(incidentStatus);
145  }
146
147  // Item type
148  K = XM.Item;
149  var itemTypeJson = [
150    { id: K.PURCHASED, name: "_purchased".loc() },
151    { id: K.MANUFACTURED, name: "_manufactured".loc() },
152    { id: K.PHANTOM, name: "_phantom".loc() },
153    { id: K.REFERENCE, name: "_reference".loc() },
154    { id: K.COSTING, name: "_costing".loc() },
155    { id: K.TOOLING, name: "_tooling".loc() },
156    { id: K.OUTSIDE_PROCESS, name: "_outsideProcess".loc() },
157    { id: K.PLANNING, name: "_planning".loc() },
158    { id: K.KIT, name: "_kit".loc() },
159    { id: K.BREEDER, name: "_breeder".loc() },
160    { id: K.CO_PRODUCT, name: "_coProduct".loc() },
161    { id: K.BY_PRODUCT, name: "_byProduct".loc() }
162  ];
163  XM.ItemTypeModel = Backbone.Model.extend();
164  XM.ItemTypeCollection = Backbone.Collection.extend({
165    model: XM.ItemTypeModel
166  });
167  XM.itemTypes = new XM.ItemTypeCollection();
168  for (i = 0; i < itemTypeJson.length; i++) {
169    var itemType = new XM.ItemTypeModel(itemTypeJson[i]);
170    XM.itemTypes.add(itemType);
171  }
172
173  // Ledger Account Type
174  K = XM.LedgerAccount;
175  var ledgerAccountTypeJson = [
176    { id: K.ASSET, name: "_asset".loc() },
177    { id: K.LIABILITY, name: "_liability".loc() },
178    { id: K.REVENUE, name: "_revenue".loc() },
179    { id: K.EXPENSE, name: "_expense".loc() },
180    { id: K.EQUITY, name: "_equity".loc() }
181  ];
182  XM.LedgerAccountTypeModel = Backbone.Model.extend({
183  });
184  XM.LedgerAccountTypeCollection = Backbone.Collection.extend({
185    model: XM.LedgerAccountTypeModel
186  });
187  XM.ledgerAccountTypes = new XM.LedgerAccountTypeCollection();
188  for (i = 0; i < ledgerAccountTypeJson.length; i++) {
189    var ledgerAccountType = new XM.LedgerAccountTypeModel(accountTypeJson[i]);
190    XM.ledgerAccountTypes.add(ledgerAccountType);
191  }
192
193  // Month (for credit cards)
194  XM.MonthModel = Backbone.Model.extend({
195  });
196  XM.MonthCollection = Backbone.Collection.extend({
197    model: XM.MonthModel
198  });
199  XM.months = new XM.MonthCollection();
200  for (i = 1; i <= 12; i++) {
201    var monthFormat = i < 10 ? "0" + i : "" + i;
202    var month = new XM.MonthModel({id: monthFormat, name: monthFormat});
203    XM.months.add(month);
204  }
205
206  // Number Policy
207  K = XM.Document;
208  var numberPolicyJson = [
209    { id: K.MANUAL_NUMBER, name: "_manual".loc() },
210    { id: K.AUTO_NUMBER, name: "_automatic".loc() },
211    { id: K.AUTO_OVERRIDE_NUMBER, name: "_automaticOverride".loc() }
212  ];
213  XM.NumberPolicyModel = Backbone.Model.extend({
214  });
215  XM.NumberPolicyCollection = Backbone.Collection.extend({
216    model: XM.NumberPolicyModel
217  });
218  XM.numberPolicies = new XM.NumberPolicyCollection();
219  for (i = 0; i < numberPolicyJson.length; i++) {
220    var numberPolicy = new XM.NumberPolicyModel(numberPolicyJson[i]);
221    XM.numberPolicies.add(numberPolicy);
222  }
223
224  // Characteristic Type
225  K = XM.Characteristic;
226  var characteristicTypeJson = [
227    { id: K.TEXT, name: "_text".loc() },
228    { id: K.LIST, name: "_list".loc() },
229    { id: K.DATE, name: "_date".loc() }
230  ];
231  XM.CharacteristicTypeModel = Backbone.Model.extend({
232  });
233  XM.CharacteristicTypeCollection = Backbone.Collection.extend({
234    model: XM.CharacteristicTypeModel
235  });
236  XM.characteristicTypes = new XM.CharacteristicTypeCollection();
237  for (i = 0; i < characteristicTypeJson.length; i++) {
238    var characteristicType = new XM.CharacteristicTypeModel(characteristicTypeJson[i]);
239    XM.characteristicTypes.add(characteristicType);
240  }
241
242  // Terms Type
243  var termsTypeJson = [
244    { id: "D", name: "_days".loc() },
245    { id: "P", name: "_proximo".loc() }
246  ];
247  XM.TermsTypeModel = Backbone.Model.extend({
248  });
249  XM.TermsTypeCollection = Backbone.Collection.extend({
250    model: XM.TermsTypeModel
251  });
252  XM.termsTypes = new XM.TermsTypeCollection();
253  for (i = 0; i < termsTypeJson.length; i++) {
254    var termsType = new XM.TermsTypeModel(termsTypeJson[i]);
255    XM.termsTypes.add(termsType);
256  }
257
258  // Hold Type
259  K = XM.SalesOrder;
260  var holdTypeJson = [
261    { id: K.CREDIT_HOLD_TYPE, name: "_credit".loc() },
262    { id: K.SHIPPING_HOLD_TYPE, name: "_shipping".loc() },
263    { id: K.PACKING_HOLD_TYPE, name: "_packing".loc() },
264    { id: K.RETURN_HOLD_TYPE, name: "_return".loc() }
265  ];
266  XM.HoldTypeModel = Backbone.Model.extend({
267  });
268  XM.HoldTypeCollection = Backbone.Collection.extend({
269    model: XM.HoldTypeModel
270  });
271  XM.holdTypes = new XM.HoldTypeCollection();
272  for (i = 0; i < holdTypeJson.length; i++) {
273    var holdType = new XM.HoldTypeModel(holdTypeJson[i]);
274    XM.holdTypes.add(holdType);
275  }
276
277  // Wage types
278  K = XM.Wage;
279  var wageTypeJson = [
280    { id: K.HOURLY, name: "_hourly".loc() },
281    { id: K.SALARIED, name: "_salaried".loc() }
282  ];
283  XM.WageTypeModel = Backbone.Model.extend();
284  XM.WageTypeCollection = Backbone.Collection.extend({
285    model: XM.WageTypeModel
286  });
287  XM.wageTypes = new XM.WageTypeCollection();
288  for (i = 0; i < wageTypeJson.length; i++) {
289    var wageType = new XM.WageTypeModel(wageTypeJson[i]);
290    XM.wageTypes.add(wageType);
291  }
292
293  // Wage periods
294  var wagePeriodJson = [
295    { id: K.HOURLY, name: "_hourly".loc() },
296    { id: K.DAILY, name: "_daily".loc() },
297    { id: K.WEEKLY, name: "_weekly".loc() },
298    { id: K.BI_WEEKLY, name: "_biWeekly".loc() },
299    { id: K.MONTHLY, name: "_monthly".loc() },
300    { id: K.ANNULY, name: "_annualy".loc() }
301  ];
302  XM.WagePeriodModel = Backbone.Model.extend();
303  XM.WagePeriodCollection = Backbone.Collection.extend({
304    model: XM.WagePeriodModel
305  });
306  XM.wagePeriods = new XM.WagePeriodCollection();
307  for (i = 0; i < wagePeriodJson.length; i++) {
308    var wagePeriod = new XM.WagePeriodModel(wagePeriodJson[i]);
309    XM.wagePeriods.add(wagePeriod);
310  }
311
312  // ToDo Status
313  K = XM.ToDo;
314  var toDoStatusJson = [
315    { id: K.PENDING, name: "_pending".loc() },
316    { id: K.DEFERRED, name: "_deferred".loc() },
317    { id: K.NEITHER, name: "_neither".loc() }
318  ];
319  XM.ToDoStatusModel = Backbone.Model.extend({
320  });
321  XM.ToDoStatusCollection = Backbone.Collection.extend({
322    model: XM.ToDoStatusModel
323  });
324  XM.toDoStatuses = new XM.ToDoStatusCollection();
325  for (i = 0; i < toDoStatusJson.length; i++) {
326    var toDoStatus = new XM.ToDoStatusModel(toDoStatusJson[i]);
327    XM.toDoStatuses.add(toDoStatus);
328  }
329
330  // Year (for credit cards)
331  XM.YearModel = Backbone.Model.extend({
332  });
333  XM.YearCollection = Backbone.Collection.extend({
334    model: XM.YearModel
335  });
336  XM.years = new XM.YearCollection();
337  for (i = 2000; i <= 2030; i++) {
338    var yearFormat = "" + i;
339    var year = new XM.YearModel({id: yearFormat, name: yearFormat});
340    XM.years.add(year);
341  }
342
343  // Sort Type
344  var sortTypeJson = [
345    { id: "ascending", name: "_ascending".loc() },
346    { id: "descending", name: "_descending".loc() }
347  ];
348  XM.SortTypeModel = Backbone.Model.extend({
349  });
350  XM.SortTypeCollection = Backbone.Collection.extend({
351    model: XM.SortTypeModel
352  });
353  XM.sortTypes = new XM.SortTypeCollection();
354  for (i = 0; i < sortTypeJson.length; i++) {
355    var sortType = new XM.SortTypeModel(sortTypeJson[i]);
356    XM.sortTypes.add(sortType);
357  }
358
359  // Attributes for Sorting and Column Layout
360  XM.Attribute = Backbone.Model.extend({});
361  XM.AttributeCollection = Backbone.Collection.extend({
362    model: XM.Attribute
363  });
364
365  // Reason Code Document Types
366  K = XM.ReasonCode;
367  var reasonDocTypeJson = [
368    { id: K.DEBIT_MEMO, name: "_debitMemo".loc() },
369    { id: K.CREDIT_MEMO, name: "_creditMemo".loc() }
370  ];
371  XM.ReasonDocTypeModel = Backbone.Model.extend({});
372  XM.ReasonDocTypeCollection = Backbone.Collection.extend({
373    model: XM.ReasonDocTypeModel
374  });
375  XM.reasonCodeDocumentTypes = new XM.ReasonDocTypeCollection();
376  for (i = 0; i < reasonDocTypeJson.length; i++) {
377    var reasonDocType = new XM.ReasonDocTypeModel(reasonDocTypeJson[i]);
378    XM.reasonCodeDocumentTypes.add(reasonDocType);
379  }
380
381  // Bank Account Types
382  K = XM.BankAccount;
383  var bankAccountTypeJson = [
384    { id: K.CASH, name: "_cash".loc() },
385    { id: K.CHECKING, name: "_checking".loc() },
386    { id: K.CREDIT_CARD, name: "_creditCard".loc() }
387  ];
388  XM.BankAccountTypeModel = Backbone.Model.extend({});
389  XM.BankAccountTypeCollection = Backbone.Collection.extend({
390    model: XM.BankAccountTypeModel
391  });
392  XM.bankAccountTypes = new XM.BankAccountTypeCollection();
393  for (i = 0; i < bankAccountTypeJson.length; i++) {
394    var bankAccountType = new XM.BankAccountTypeModel(bankAccountTypeJson[i]);
395    XM.bankAccountTypes.add(bankAccountType);
396  }
397
398  // Workflow Status
399  K = XM.Workflow;
400  var workflowStatusJson = [
401    { id: K.PENDING, name: "_pending".loc() },
402    { id: K.IN_PROCESS, name: "_inProcess".loc() },
403    { id: K.COMPLETED, name: "_completed".loc() },
404    { id: K.DEFERRED, name: "_deferred".loc() },
405  ];
406  XM.WorkflowStatusModel = Backbone.Model.extend({});
407  XM.WorkflowStatusCollection = Backbone.Collection.extend({
408    model: XM.WorkflowStatusModel
409  });
410  XM.workflowStatuses = new XM.WorkflowStatusCollection();
411  for (i = 0; i < workflowStatusJson.length; i++) {
412    var workflowStatus = new XM.WorkflowStatusModel(workflowStatusJson[i]);
413    XM.workflowStatuses.add(workflowStatus);
414  }
415
416  // Workflow Type
417  var salesOrderWorkflowTypeJson = [
418    { id: XM.SalesOrderWorkflow.TYPE_OTHER, name: "_other".loc() },
419    { id: XM.SalesOrderWorkflow.TYPE_CREDIT_CHECK, name: "_creditCheck".loc() }//,
420  ];
421  XM.SalesOrderWorkflowTypeModel = Backbone.Model.extend({});
422  XM.SalesOrderWorkflowTypeCollection = Backbone.Collection.extend({
423    model: XM.SalesOrderWorkflowTypeModel
424  });
425  XM.salesOrderWorkflowTypes = new XM.SalesOrderWorkflowTypeCollection();
426  _.each(salesOrderWorkflowTypeJson, function (obj) {
427    XM.salesOrderWorkflowTypes.add(new XM.SalesOrderWorkflowTypeModel(obj));
428  });
429
430  // Project Status
431  K = XM.ProjectStatusMixin;
432  var projectStatusJson = [
433    { id: K.CONCEPT, name: "_concept".loc() },
434    { id: K.REVIEW, name: "_review".loc() },
435    { id: K.REVISION, name: "_revision".loc() },
436    { id: K.APPROVED, name: "_approved".loc() },
437    { id: K.IN_PROCESS, name: "_inProcess".loc() },
438    { id: K.COMPLETED, name: "_completed".loc() },
439    { id: K.REJECTED, name: "_rejected".loc() }
440  ];
441  XM.ProjectStatusModel = Backbone.Model.extend({
442  });
443  XM.ProjectStatusCollection = Backbone.Collection.extend({
444    model: XM.ProjectStatusModel
445  });
446  XM.projectStatuses = new XM.ProjectStatusCollection();
447  for (i = 0; i < projectStatusJson.length; i++) {
448    var projectStatus = new XM.ProjectStatusModel(projectStatusJson[i]);
449    XM.projectStatuses.add(projectStatus);
450  }
451
452  // Sales Order
453  K = XM.SalesOrder;
454  var salesOrderStatusesJson = [
455    { id: K.OPEN_STATUS, name: "_open".loc() },
456    { id: K.CLOSED_STATUS, name: "_closed".loc() },
457    { id: K.CANCELLED_STATUS, name: "_cancelled".loc() }
458  ];
459  XM.SalesOrderStatusModel = Backbone.Model.extend({
460  });
461  XM.SalesOrderStatusCollection = Backbone.Collection.extend({
462    model: XM.SalesOrderStatusModel
463  });
464  XM.salesOrderStatuses = new XM.SalesOrderStatusCollection();
465  for (i = 0; i < salesOrderStatusesJson.length; i++) {
466    var SalesOrderStatus = new XM.SalesOrderStatusModel(salesOrderStatusesJson[i]);
467    XM.salesOrderStatuses.add(SalesOrderStatus);
468  }
469
470}());