ShareObjectUI.js
7.05 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
* Project : AMDA-NG
* Name : ShareObjectUI.js
* @class amdaUI.ShareObjectUI
* @extends Ext.form.Panel
* @brief Share object UI definition (View)
* @author Benjamin
* @version $Id: $
********************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
*/
Ext.define('amdaUI.ShareObjectUI',{
extend: 'Ext.form.Panel',
alias: 'widget.shareobject',
infoTextArea : null,
folderStore : null,
folderCombo : null,
nameField : null,
descriptionTextArea : null,
objectType : 'unknown',
objectProp : null,
onAfterShareObject : null,
constructor: function(config) {
this.init(config);
this.callParent(arguments);
},
setProperties: function(objectType, objProp) {
var typeName = '';
switch (objectType) {
case 'timetab' :
typeName = 'TimeTable';
break;
case 'catalog' :
typeName = 'Catalog';
break;
default:
typeName = 'Unknown Type';
}
this.objectType = objectType;
this.objectProp = objProp;
var message = 'Do you really want to share "' + objProp.name + '" to the community?';
message += '\n\nNote: You will not be able to delete or change this object once shared.';
this.infoTextArea.setValue(message);
this.nameField.setValue(objProp.name);
//Update folders list
AmdaAction.getSharedObjectFolders({'type' : this.objectType}, function (result, e) {
var t = e.getTransaction();
if (e.status)
{
if (result && result.success)
{
this.folderCombo.store.loadData(result.folders, false);
}
else
Ext.Msg.show( {
title : 'Share Object',
msg : 'Cannot get folder list ('+result.message+')',
modal : true,
icon : Ext.Msg.ERROR,
buttons : Ext.Msg.OK
});
}
else
{
// FAILURE
Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
},this);
},
init : function(config) {
var me = this;
//Callback called when a new shared object is added
if (config.onAfterShareObject)
me.onAfterShareObject = config.onAfterShareObject;
this.infoTextArea = Ext.create('Ext.form.field.TextArea', {
xtype : 'textareafield',
hideLabel : true,
autoScroll : true,
});
this.folderStore = Ext.create('Ext.data.Store', {
fields: ['id', 'name'],
data : [],
listeners: {
datachanged : function(store) {
if ((store.getCount() <= 0) || !me.folderCombo)
return;
me.folderCombo.select(store.getAt(0));
}
}
});
this.folderCombo = Ext.create('Ext.form.field.ComboBox', {
fieldLabel: 'Choose Folder',
store: this.folderStore,
queryMode: 'local',
displayField: 'name',
valueField: 'id',
value: 'None',
editable: false,
forceSelection: true
});
this.nameField = Ext.create('Ext.form.field.Text', {
fieldLabel: 'Name',
allowBlank: false // requires a non-empty value
});
this.descriptionTextArea = Ext.create('Ext.form.field.TextArea', {
xtype : 'textareafield',
fieldLabel: 'Description',
autoScroll : true,
allowBlank : false // requires a non-empty value
});
var myConf = {
layout: {
type: 'vbox',
align: 'stretch'
},
items: [
this.infoTextArea,
this.folderCombo,
this.nameField,
this.descriptionTextArea
],
fbar: [
{
text: 'Share',
scope: this,
handler: function() {
if(!me.isValid())
return;
var folder = me.folderCombo.getValue();
var description = me.descriptionTextArea.getValue();
var name = me.nameField.getValue();
AmdaAction.isSharedObjectNameAlreadyUsed({'type' : me.objectType, 'name' : name}, function (result, e) {
var t = e.getTransaction();
if (e.status)
{
if (result && result.success)
{
var request_obj = {
'type' : me.objectType,
'object' : me.objectProp,
'folder' : folder,
'name' : name,
'description' : description
};
if (result.alreadyUsed)
{
Ext.Msg.show( {
title : 'Share Object',
msg : 'Name "' + name + '" already used',
modal : true,
icon : Ext.Msg.ERROR,
buttons : Ext.Msg.OK
});
return;
}
AmdaAction.shareObjects(request_obj, function (result, e) {
var t = e.getTransaction();
if (e.status)
{
if (result && result.success)
{
if (me.onAfterShareObject)
me.onAfterShareObject(result.folder_id, result.object_id);
}
else
Ext.Msg.show( {
title : 'Share Object',
msg : 'Cannot share objects ('+result.message+')',
modal : true,
icon : Ext.Msg.ERROR,
buttons : Ext.Msg.OK
});
}
else
{
// FAILURE
Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
},me);
}
else
Ext.Msg.show( {
title : 'Share Object',
msg : 'Cannot share objects ('+result.message+')',
modal : true,
icon : Ext.Msg.ERROR,
buttons : Ext.Msg.OK
});
}
else
{
// FAILURE
Ext.Msg.show({title:'Error System', msg: e.message, icon: Ext.MessageBox.ERROR, buttons: Ext.Msg.OK});
}
});
}
}
]
};
Ext.apply (this , Ext.apply (arguments, myConf));
}
});