Update module_container.js
[xtuple] / enyo-client / application / source / views / module_container.js
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*/
4 /*global XT:true, XV:true, XM:true, _:true, enyo:true, window:true */
5
6 (function () {
7
8   enyo.kind({
9     name: "XV.Postbooks",
10     kind: "XV.ModuleContainer",
11     handlers: {
12       onNoBaseCurr: "handleNoBaseCurr"
13     },
14     modules: [
15       {name: "welcome", label: "_welcome".loc(), hasSubmenu: false,
16         panels: [
17         {name: "welcomePage",
18           tag: "iframe",
19           style: "border: none;"}
20       ]},
21       {name: "setup", label: "_setup".loc(), sortAlpha: true, panels: [
22         {name: "configureList", kind: "XV.ConfigurationsList", toggleSelected: false},
23         {name: "userAccountList", kind: "XV.UserAccountList", toggleSelected: false},
24         {name: "userAccountRoleList", kind: "XV.UserAccountRoleList"}
25       ]}
26     ],
27     activate: function () {
28       // Look for welcome page and set to what settings say to
29       var children = this.$.navigator.$.contentPanels.children,
30         welcome = _.findWhere(children, {name: "welcomePage"}),
31         url = XT.session.settings.get("MobileWelcomePage"),
32         params = "?client=mobileweb" +
33           //"&username=" + XT.session.details.id +
34           "&hostname=" + window.location.hostname +
35           "&organization=" + XT.session.details.organization +
36           "&version=" + XT.session.config.version;
37
38       if (welcome && url) {
39         welcome.setAttributes({src: url + params});
40       }
41       this.inherited(arguments);
42     },
43     handleNoBaseCurr: function () {
44       var that = this,
45         wsCallback = function (model) {
46           // If workspace was not saved, prompt again.
47           if (model) {
48             return;
49           } else {
50             that.handleNoBaseCurr();
51           }
52         };
53
54       this.notify(this, {
55         type: XM.Model.QUESTION,
56         message: "_selectBaseCurrency".loc(),
57         yesLabel: "_setBaseCurrToUSD".loc(),
58         noLabel: "_createBaseCurr".loc(),
59         callback: function (response) {
60           if (!response.answer) {
61             // User doesn't want to use USD, open Currency workspace
62             that.addWorkspace(null, {
63               workspace: "XV.CurrencyWorkspace",
64               attributes: {
65                 isBase: true
66               },
67               callback: wsCallback
68             });
69
70           // User confirms that they want to use USD, open USD workspace, set isBase
71           } else if (response.answer) {
72             that.addWorkspace(null, {
73               workspace: "XV.CurrencyWorkspace",
74               id: "USD",
75               attributes: {
76                 isBase: true
77               },
78               callback: wsCallback,
79               success: function () {
80                 this.$.isBase.setValue(true);
81               }
82             });
83           }
84         }
85       });
86     }
87   });
88 }());