aboutsummaryrefslogtreecommitdiffstats
path: root/source/moduleManagerDesktop.js
blob: c2ee1bdff3934f0bfdc0502ae177027dbdcd98fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
enyo.kind({
    name: "biblez.moduleManagerDesktop",
    kind: "enyo.FittableRows",
    fit: true,
    events: {
        onBack: "",
        onInstalled: ""
    },
    components: [
        {name: "messagePopup", kind: "onyx.Popup", scrim: true, centered: true, floating: true, classes: "message-popup"},
        {name: "scrim", kind: "onyx.Scrim", classes: "onyx-scrim-translucent"},
        {kind: "onyx.MoreToolbar", components: [
            {kind: "onyx.IconButton", src: "assets/back.png", ontap: "handleBack"},
            {content: $L("Module Manager")}
            //{kind: "onyx.IconButton", src: "assets/delete.png", ontap: "clearDB"}
        ]},
        {kind: "enyo.Scroller", fit: true, classes: "center settings-container", components: [
            {content: $L("Download a zipped module from one of the following repositories:")},
            {allowHtml: true, content: "<ul><li><a target='_blank' href='http://www.crosswire.org/sword/modules/ModDisp.jsp?modType=Bibles'>CrossWire Main</a></li>" +
                                        "<li><a target='_blank' href='http://www.crosswire.org/sword/modules/ModDisp.jsp?modType=Bibles&av=true'>CrossWire av11n</a></li>" +
                                        "<li><a target='_blank' href='http://www.crosswire.org/sword/modules/ModDisp.jsp?modType=Bibles&beta=true'>CrossWire Beta</a></li></ul>"
            },
            {content: $L("To install the module, select the module file!")},
            {kind: "onyx.Input", type: "file", id: "files", name: "files[]", onchange: "installModule"},
            {tag: "br"},
            {kind: "onyx.Spinner", name: "spinner", showing: false, classes: "onyx-light center"},
            {tag: "br"},
            {name: "gbModules", showing: false, kind: "onyx.Groupbox", components: [
                {kind: "onyx.GroupboxHeader", content: $L("Installed Modules")},
                {name: "moduleList", kind: "Repeater", count: 0, onSetupItem: "setupModules", components: [
                    {kind: "enyo.FittableColumns", classes: "settings-row item", components: [
                        {name: "moduleName", style: "line-height: 35px;", fit: true},
                        {name: "btRemove", modKey: null, kind: "onyx.Button", content: "Remove", classes: "onyx-negative", ontap: "handleRemove"}
                    ]}
                ]}
            ]}
        ]}
    ],

    modules: [],

    rendered: function () {
        this.inherited(arguments);
        this.getModules();
    },

    getModules: function () {
        sword.moduleMgr.getModules(enyo.bind(this, function(inError, inModules) {
            if (!inError) {
                if(inModules.length !== 0) {
                    this.$.gbModules.show();
                } else if (inModules.length === 0) {
                    this.$.gbModules.hide();
                }
                this.modules = inModules;
                this.$.moduleList.setCount(this.modules.length);
            } else {
                this.handleError(inError);
            }
        }));
    },

    handleBack: function() {
        this.doBack();
    },

    installModule: function (inSender, inEvent) {
        this.$.spinner.start();
        sword.installMgr.installModule(inEvent.target.files[0], enyo.bind(this, function (inError, inModule) {
            if (!inError) {
                this.doInstalled();
                this.getModules();
                this.$.spinner.stop();
                this.handleError("Installed Module!");
            } else {
                this.handleError((inError.message) ? inError.message : inError);
            }
        }));
    },

    setupModules: function (inSender, inEvent) {
        var index = inEvent.index;
        var item = inEvent.item;
        item.$.moduleName.setContent(this.modules[index].modKey);
        item.$.btRemove.modKey = this.modules[index].modKey;
        return true;
    },

    handleRemove: function (inSender, inEvent) {
        if(inEvent.originator && inEvent.originator.modKey) {
            sword.installMgr.removeModule(inEvent.originator.modKey, enyo.bind(this, function (inError) {
                if(!inError) {
                    this.doInstalled();
                    this.getModules();
                } else {
                    this.handleError(inError);
                }
            }));
        }
        return true;
    },

    handleError: function (inMessage) {
        if (inMessage.message)
            inMessage = inMessage.message;
        this.$.messagePopup.setContent(inMessage);
        this.$.messagePopup.show();
    }
});