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