1
|
|
|
/** |
2
|
|
|
* @copyright Copyright (C) 2008 - 2016 redCOMPONENT.com. All rights reserved. |
3
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
// Only define the redCORE namespace if not defined. |
7
|
|
|
redCORE = window.redCORE || {}; |
|
|
|
|
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Method to get the event target and optionally target the parent of an icon element |
11
|
|
|
*/ |
12
|
|
|
redCORE.getTarget = function(event, clearIcon) |
13
|
|
|
{ |
14
|
|
|
// IE or every other browser |
15
|
|
|
var targ = event.target || event.srcElement; |
16
|
|
|
|
17
|
|
|
if (clearIcon && targ.tagName == 'I') |
18
|
|
|
{ |
19
|
|
|
targ = targ.parentElement; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
return targ; |
23
|
|
|
}; |
24
|
|
|
|
25
|
|
|
redCORE.ws = |
26
|
|
|
{ |
27
|
|
|
init:function() |
28
|
|
|
{ |
29
|
|
|
jQuery('body') |
30
|
|
|
.on('click', '.fields-add-new-row', redCORE.ws.addNewRow) |
31
|
|
|
.on('click', '.fields-remove-row', redCORE.ws.removeRow) |
32
|
|
|
.on('click', '.ws-data-mode-switch input', redCORE.ws.toggleDataMode) |
33
|
|
|
.on('click', '.ws-validate-data-switch input', redCORE.ws.toggleValidateDataSwitch) |
34
|
|
|
.on('click', '.ws-documentationSource-switch input', redCORE.ws.toggleDocumentSource) |
35
|
|
|
.on('click', '.ws-use-forward-switch input', redCORE.ws.toggleForwardSwitch) |
36
|
|
|
.on('click', '.ws-isEnabled-trigger input', redCORE.ws.toggleEnabled) |
37
|
|
|
.on('click', '.fields-add-new-task', redCORE.ws.addNewTask) |
38
|
|
|
.on('click', '.fields-add-new-type',redCORE.ws.addNewType) |
39
|
|
|
.on('click', '.fields-edit-row', redCORE.ws.toggleEditRow) |
40
|
|
|
.on('click', '.fields-apply-row', redCORE.ws.toggleEditRow); |
41
|
|
|
}, |
42
|
|
|
|
43
|
|
|
addNewTask: function(event) |
44
|
|
|
{ |
45
|
|
|
event.preventDefault(); |
46
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
47
|
|
|
|
48
|
|
|
var getData = {}; |
49
|
|
|
getData.taskName = targ.parents('.fields-add-new-task-row').find('[name="newTask"]').val().replace(/[^\w]/g,''); |
50
|
|
|
|
51
|
|
|
if (getData.taskName == '') |
52
|
|
|
{ |
53
|
|
|
var msg = targ.attr('data-no-task-msg'); |
54
|
|
|
alert(msg); |
55
|
|
|
|
56
|
|
|
return false; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
jQuery.ajax({ |
60
|
|
|
url: 'index.php?option=com_redcore&task=webservice.ajaxGetTask', |
61
|
|
|
data: getData, |
62
|
|
|
dataType: 'text', |
63
|
|
|
beforeSend: function () |
64
|
|
|
{ |
65
|
|
|
targ.parents('#webserviceTabTask').addClass('opacity-40'); |
66
|
|
|
} |
67
|
|
|
}).done(function (data){ |
68
|
|
|
targ.parents('#webserviceTabTask').removeClass('opacity-40') |
69
|
|
|
.find('.tab-content:first').prepend(data); |
70
|
|
|
|
71
|
|
|
redCORE.ws.addTabLink('#taskTabs', getData.taskName, 'task'); |
72
|
|
|
|
73
|
|
|
jQuery('select').chosen(); |
74
|
|
|
jQuery('.hasTooltip').tooltip(); |
75
|
|
|
rRadioGroupButtonsSet('#operationTabtask-' + getData.taskName); |
76
|
|
|
rRadioGroupButtonsEvent('#operationTabtask-' + getData.taskName); |
77
|
|
|
jQuery('#operationTabtask-' + getData.taskName + ' :input[checked="checked"]').click(); |
78
|
|
|
}); |
|
|
|
|
79
|
|
|
}, |
80
|
|
|
|
81
|
|
|
addTabLink: function (id, tabIdFragment, prefix) |
82
|
|
|
{ |
83
|
|
|
var html = '<li><a href="#operationTab' + prefix + '-' |
84
|
|
|
+ tabIdFragment + '" id="operation-' + prefix + '-' |
85
|
|
|
+ tabIdFragment + '-tab" data-toggle="tab">' + prefix + '-' |
86
|
|
|
+ tabIdFragment + '</a></li>'; |
87
|
|
|
|
88
|
|
|
jQuery(id).prepend(html).find('li a:first').click(); |
89
|
|
|
|
90
|
|
|
}, |
91
|
|
|
|
92
|
|
|
addNewType: function(event) |
93
|
|
|
{ |
94
|
|
|
event.preventDefault(); |
95
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
96
|
|
|
|
97
|
|
|
var getData = {}; |
98
|
|
|
getData.typeName = targ.parents('.fields-add-new-type-row').find('[name="newType"]').val().replace(/[^\w]/g,''); |
99
|
|
|
|
100
|
|
|
if (getData.typeName == '') |
101
|
|
|
{ |
102
|
|
|
var msg = targ.attr('data-no-type-msg'); |
103
|
|
|
alert(msg); |
104
|
|
|
|
105
|
|
|
return false; |
106
|
|
|
} |
107
|
|
|
|
108
|
|
|
jQuery.ajax({ |
109
|
|
|
url: 'index.php?option=com_redcore&task=webservice.ajaxAddComplexType', |
110
|
|
|
data: getData, |
111
|
|
|
dataType: 'text', |
112
|
|
|
beforeSend: function () |
113
|
|
|
{ |
114
|
|
|
targ.parents('#webserviceTabComplexTypes').addClass('opacity-40'); |
115
|
|
|
} |
116
|
|
|
}).done(function (data){ |
117
|
|
|
targ.parents('#webserviceTabComplexTypes').removeClass('opacity-40') |
118
|
|
|
.find('.tab-content:first').prepend(data); |
119
|
|
|
|
120
|
|
|
redCORE.ws.addTabLink('#typeTabs', getData.typeName, 'type'); |
121
|
|
|
jQuery('select').chosen(); |
122
|
|
|
jQuery('.hasTooltip').tooltip(); |
123
|
|
|
rRadioGroupButtonsSet('#operationTabtype-' + getData.typeName); |
124
|
|
|
rRadioGroupButtonsEvent('#operationTabtype-' + getData.typeName); |
125
|
|
|
jQuery('#operationTabtype-' + getData.typeName + ' :input[checked="checked"]').click(); |
126
|
|
|
}); |
|
|
|
|
127
|
|
|
}, |
128
|
|
|
|
129
|
|
|
addNewRow: function(event) |
130
|
|
|
{ |
131
|
|
|
event.preventDefault(); |
132
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
133
|
|
|
var id = targ.closest('form').find('input[name="id"]'); |
134
|
|
|
|
135
|
|
|
var getData = {}; |
136
|
|
|
getData.operation = targ.find('[name="addNewRowOperation"]').val(); |
137
|
|
|
getData.fieldList = targ.find('[name="addNewRowList"]').val(); |
138
|
|
|
|
139
|
|
|
var rowType = targ.find('[name="addNewRowType"]').val(); |
140
|
|
|
var optionType = targ.find('[name="addNewOptionType"]').val(); |
141
|
|
|
|
142
|
|
|
if (typeof optionType == 'undefined') |
143
|
|
|
{ |
144
|
|
|
optionType = rowType; |
145
|
|
|
} |
146
|
|
|
|
147
|
|
|
if (optionType == 'FieldFromDatabase' || optionType == 'ResourceFromDatabase') |
148
|
|
|
{ |
149
|
|
|
getData['tableName'] = targ.parents('.form-inline:first').find('[name="jform[main][addFromDatabase]"]').val(); |
150
|
|
|
} |
151
|
|
|
else if (optionType == 'ConnectWebservice') |
152
|
|
|
{ |
153
|
|
|
getData['webserviceId'] = targ.parents('.form-inline:first').find('[name="jform[main][connectWebservice]"]').val(); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
jQuery.ajax({ |
157
|
|
|
url: 'index.php?option=com_redcore&task=webservice.ajaxGet' + optionType + '&id=' + id.val(), |
158
|
|
|
data: getData, |
159
|
|
|
dataType: 'text', |
160
|
|
|
beforeSend: function () |
161
|
|
|
{ |
162
|
|
|
targ.parents('fieldset:first').addClass('opacity-40'); |
163
|
|
|
} |
164
|
|
|
}).done(function(data) |
165
|
|
|
{ |
166
|
|
|
targ.parents('fieldset:first').removeClass('opacity-40') |
167
|
|
|
.find('.ws-row-list').prepend(data) |
168
|
|
|
.find('.fields-edit-row:first').click(); |
169
|
|
|
jQuery('select').chosen(); |
170
|
|
|
jQuery('.hasTooltip').tooltip(); |
171
|
|
|
rRadioGroupButtonsSet('.ws-' + rowType + '-' + getData['operation']); |
172
|
|
|
rRadioGroupButtonsEvent('.ws-' + rowType + '-' + getData['operation']); |
173
|
|
|
}) |
174
|
|
|
}, |
175
|
|
|
|
176
|
|
|
removeRow:function(event) |
177
|
|
|
{ |
178
|
|
|
event.preventDefault(); |
179
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
180
|
|
|
targ.parents('.row-stripped').remove(); |
181
|
|
|
}, |
182
|
|
|
|
183
|
|
|
toggleEditRow: function(event) |
184
|
|
|
{ |
185
|
|
|
event.preventDefault(); |
186
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
187
|
|
|
var parent = targ.parents('.row-stripped'); |
188
|
|
|
|
189
|
|
|
var editRow = parent.find('.ws-row-edit'); |
190
|
|
|
var displayRow = parent.find('.ws-row-display'); |
191
|
|
|
|
192
|
|
|
if (editRow.css('display') == 'none') |
193
|
|
|
{ |
194
|
|
|
editRow.show(); |
195
|
|
|
displayRow.hide(); |
196
|
|
|
|
197
|
|
|
return true; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
var rowValues = {}; |
201
|
|
|
|
202
|
|
|
parent.find('.ws-row-edit :input') |
203
|
|
|
.each(function() |
204
|
|
|
{ |
205
|
|
|
var input = jQuery(this); |
206
|
|
|
var name = input.attr('name'); |
207
|
|
|
|
208
|
|
|
if ((!input.is(':radio') || input.prop('checked')) && typeof name !== typeof undefined && name !== false) |
209
|
|
|
{ |
210
|
|
|
if (input.is(':radio')){ |
211
|
|
|
name = name.split('_'); |
212
|
|
|
name = name[1]; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
var displayCell = parent.find('.ws-row-display-cell-' + name); |
216
|
|
|
displayCell.html(input.val()); |
217
|
|
|
displayCell.parent().show(); |
218
|
|
|
rowValues[name] = input.val(); |
219
|
|
|
} |
220
|
|
|
}); |
221
|
|
|
|
222
|
|
|
parent.find('.ws-row-original').val(JSON.stringify(rowValues)); |
223
|
|
|
editRow.hide(); |
224
|
|
|
displayRow.show(); |
|
|
|
|
225
|
|
|
}, |
226
|
|
|
|
227
|
|
|
toggleEnabled: function(event) |
228
|
|
|
{ |
229
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
230
|
|
|
var parent = targ.parents('.ws-operation-configuration'); |
231
|
|
|
parent.prop('disabled', targ.val() == 0) |
232
|
|
|
.find('chzn-done').prop('disabled', targ.val() == 0) |
233
|
|
|
.trigger('liszt:updated'); |
234
|
|
|
}, |
235
|
|
|
|
236
|
|
|
toggleForwardSwitch:function(event) |
237
|
|
|
{ |
238
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
239
|
|
|
|
240
|
|
|
if(targ.val() != '') |
241
|
|
|
{ |
242
|
|
|
targ.parents('.ws-params').find('.ws-use-operation-fieldset').hide(); |
243
|
|
|
|
244
|
|
|
return true; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
targ.parents('.ws-params').find('.ws-use-operation-fieldset').show(); |
|
|
|
|
248
|
|
|
}, |
249
|
|
|
|
250
|
|
|
toggleDocumentSource: function(event) |
251
|
|
|
{ |
252
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
253
|
|
|
var dataMode = targ.val(); |
254
|
|
|
var currentTab = targ.parents('.ws-params'); |
255
|
|
|
|
256
|
|
|
redCORE.ws.toggleByDataMode(currentTab, '.ws-documentationSource', dataMode); |
257
|
|
|
}, |
258
|
|
|
|
259
|
|
|
toggleValidateDataSwitch:function(event) |
260
|
|
|
{ |
261
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
262
|
|
|
var dataMode = targ.val(); |
263
|
|
|
var currentTab = targ.parents('.ws-params'); |
264
|
|
|
|
265
|
|
|
redCORE.ws.toggleByDataMode(currentTab, '.ws-validateData', dataMode); |
266
|
|
|
}, |
267
|
|
|
|
268
|
|
|
toggleDataMode: function(event) |
269
|
|
|
{ |
270
|
|
|
var targ = jQuery(redCORE.getTarget(event, true)); |
271
|
|
|
var dataMode = targ.val(); |
272
|
|
|
var currentTab = targ.parents('.ws-params'); |
273
|
|
|
|
274
|
|
|
redCORE.ws.toggleByDataMode(currentTab, '.ws-dataMode', dataMode); |
275
|
|
|
}, |
276
|
|
|
|
277
|
|
|
toggleByDataMode:function(currentTab, targetClass,dataMode) |
278
|
|
|
{ |
279
|
|
|
currentTab.find(targetClass).hide(); |
280
|
|
|
currentTab.find(targetClass + '-' + dataMode).show(); |
281
|
|
|
} |
282
|
|
|
}; |
283
|
|
|
|