Project

General

Profile

Download (6.57 KB) Statistics
| Branch: | Revision:

git_sitools_idoc / flarecast / workspace / client-admin / js / guiservices / GuiServicesCrud.js @ master

1
/***************************************
2
* Copyright 2010-2014 CNES - CENTRE NATIONAL d'ETUDES SPATIALES
3
* 
4
* This file is part of SITools2.
5
* 
6
* SITools2 is free software: you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation, either version 3 of the License, or
9
* (at your option) any later version.
10
* 
11
* SITools2 is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with SITools2.  If not, see <http://www.gnu.org/licenses/>.
18
***************************************/
19
/*global Ext, sitools, ID, i18n, document, showResponse, alertFailure, LOCALE, ImageChooser, 
20
 showHelp, loadUrl*/
21
Ext.namespace('sitools.admin.guiservices');
22

    
23
/**
24
 * A Panel to show all the project modules in Sitools2
25
 * 
26
 * @cfg {String} the url where get the resource
27
 * @cfg {Ext.data.JsonStore} the store where saved the project modules data
28
 * @class sitools.admin.projects.modules.ProjectModulesCrud
29
 * @extends Ext.grid.GridPanel
30
 */
31
Ext.define('sitools.admin.guiservices.GuiServicesCrud', { 
32
    extend : 'Ext.grid.Panel',
33
        alias : 'widget.s-guiservices',
34
    border : false,
35
    height : ADMIN_PANEL_HEIGHT,
36
    id : ID.BOX.GUISERVICES,
37
    pageSize : ADMIN_PANEL_NB_ELEMENTS,
38
    forceFit : true,
39
    mixins : {
40
        utils : "sitools.admin.utils.utils"
41
    },
42
    
43
    requires : ["sitools.admin.guiservices.GuiServicesStore"/*,
44
                "sitools.admin.guiservices.GuiServicesProp"*/],
45

    
46
    initComponent : function () {
47
        
48
        this.url = loadUrl.get('APP_URL') + loadUrl.get('APP_GUI_SERVICES_URL');
49
        
50
        this.store = Ext.create("sitools.admin.guiservices.GuiServicesStore", {
51
            url : this.url,
52
            pageSize : this.pageSize
53
        });
54
        
55
        this.columns = [{
56
            header : i18n.get('label.name'),
57
            dataIndex : 'name',
58
            width : 150,
59
            sortable : true,
60
            renderer : function (value, meta, record) {
61
                meta.style = "font-weight: bold;";
62
                return value;
63
            }
64
        }, {
65
            header : i18n.get('label.description'),
66
            dataIndex : 'description',
67
            width : 250,
68
            sortable : false
69
        }, {
70
            header : i18n.get('label.xtype'),
71
            dataIndex : 'xtype',
72
            width : 300,
73
            sortable : false
74
        }, {
75
            xtype : 'checkcolumn',
76
            header : i18n.get('headers.defaultGuiService'),
77
            dataIndex : 'defaultGuiService',
78
            editable : false,
79
            width : 55,
80
            processEvent: function () { return false; },
81
            sortable : false
82
        }];
83

    
84
        this.bbar = {
85
            xtype : 'pagingtoolbar',
86
            pageSize : this.pageSize,
87
            store : this.store,
88
            displayInfo : true,
89
            displayMsg : i18n.get('paging.display'),
90
            emptyMsg : i18n.get('paging.empty')
91
        };
92

    
93
        this.tbar = {
94
            xtype : 'toolbar',
95
            defaults : {
96
                scope : this
97
            },
98
            items : [ {
99
                text : i18n.get('label.create'),
100
                icon : loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL')+'/res/images/icons/toolbar_create.png',
101
                handler : this._onCreate,
102
                xtype : 's-menuButton'
103
            }, {
104
                text : i18n.get('label.modify'),
105
                icon : loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL')+'/res/images/icons/toolbar_edit.png',
106
                handler : this._onModify,
107
                xtype : 's-menuButton'
108
            }, {
109
                text : i18n.get('label.delete'),
110
                icon : loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL')+'/res/images/icons/toolbar_delete.png',
111
                handler : this._onDelete,
112
                xtype : 's-menuButton'
113
            }, '->', {
114
                xtype : 's-filter',
115
                emptyText : i18n.get('label.search'),
116
                store : this.store,
117
                pageSize : this.pageSize
118
            } ]
119
        };
120

    
121
        this.listeners = {
122
            scope : this, 
123
            itemdblclick : this._onModify
124
        };
125
        
126
        this.selModel = Ext.create('Ext.selection.RowModel', {
127
            mode : "SINGLE"
128
        });
129

    
130
        this.callParent(arguments);
131
    },
132

    
133
    /**
134
     * done a specific render to load project modules informations from the store. 
135
     */
136
    onRender : function () {
137
        this.callParent(arguments);
138
        this.store.load({
139
            start : 0,
140
            limit : this.pageSize
141
        });
142
    },
143

    
144
    /**
145
     * Open a {sitools.admin.projects.modules.ProjectModuleProp} project property panel
146
     *  to create a new project module
147
     */
148
    _onCreate : function () {
149
        var dbp = Ext.create("sitools.admin.guiservices.GuiServicesProp", {
150
            action : 'create',
151
            store : this.store
152
        });
153
        dbp.show(ID.PROP.GUISERVICES);
154
    },
155

    
156
    /**
157
     * Open a {sitools.admin.projects.modules.ProjectModuleProp} project property panel
158
     *  to modify an existing project module
159
     */
160
    _onModify : function () {
161
        var rec = this.getLastSelectedRecord();
162
        if (!rec) {
163
            return popupMessage("", i18n.get('warning.noselection'), loadUrl.get('APP_URL') + loadUrl.get('APP_CLIENT_PUBLIC_URL')+'/res/images/msgBox/16/icon-info.png');;
164
        }
165

    
166
        var dbp = Ext.create("sitools.admin.guiservices.GuiServicesProp", {
167
            action : 'modify',
168
            store : this.store,
169
            recordId : rec.data.id
170
        });
171
        dbp.show(ID.PROP.GUISERVICES);
172
    },
173

    
174
    /**
175
     * Diplay confirm delete Msg box and call the method doDelete
176
     */
177
    _onDelete : function () {
178
        var rec = this.getLastSelectedRecord();
179
        if (!rec) {
180
            return false;
181
        }
182

    
183
        Ext.Msg.show({
184
            title : i18n.get('label.delete'),
185
            buttons : Ext.Msg.YESNO,
186
            msg : Ext.String.format(i18n.get('guiServicesCrud.delete'), rec.get('name')),
187
            scope : this,
188
            fn : function (btn, text) {
189
                if (btn === 'yes') {
190
                    this.doDelete(rec);
191
                }
192
            }
193
        });
194
    },
195
    
196
    /**
197
     * done the delete of the passed record
198
     * @param rec the record to delete
199
     */
200
    doDelete : function (rec) {
201
        this.store.deleteRecord(rec);
202
    }
203

    
204
});
205