|
1 | 1 | // Global vars
|
2 | 2 | var frontendServiceUrl;
|
3 | 3 | var i = 0;
|
| 4 | +var isReplacing = true; |
4 | 5 | var ruleTemplate = {
|
5 | 6 | "TemplateName" : "",
|
6 | 7 | "Type" : "",
|
@@ -189,91 +190,105 @@ jQuery(document).ready(
|
189 | 190 | sticky : false,
|
190 | 191 | theme : 'Notify'
|
191 | 192 | });
|
192 |
| - |
| 193 | + |
193 | 194 | var list = JSON.parse(fileContent);
|
194 |
| - if (isRules == true) { |
195 |
| - vm.rulesBindingList([]); |
| 195 | + if (isRules) { |
| 196 | + if (isReplacing) { |
| 197 | + vm.rulesBindingList([]); |
| 198 | + } |
196 | 199 | list.forEach(function(element) {
|
197 | 200 | vm.addRule(element);
|
198 | 201 | });
|
199 | 202 | } else {
|
200 |
| - vm.eventsBindingList([]); |
| 203 | + if (isReplacing) { |
| 204 | + vm.eventsBindingList([]); |
| 205 | + } |
201 | 206 | list.forEach(function(element) {
|
202 | 207 | vm.addEvent(element);
|
203 | 208 | });
|
204 | 209 | }
|
205 | 210 | };
|
206 |
| - |
| 211 | + |
207 | 212 | if (subscriptionFile != null){
|
208 | 213 | reader.readAsText(subscriptionFile);
|
209 | 214 | }
|
210 | 215 | }
|
211 | 216 |
|
212 |
| - //Set onchange event on the input element "uploadRulesFile" and "uploadEventsFile" |
213 |
| - var pomRules = document.getElementById('uploadRulesFile'); |
214 |
| - pomRules.onchange = function uploadFinished() { |
215 |
| - var subscriptionFile = pomRules.files[0]; |
216 |
| - validateJSONAndUpload(subscriptionFile, true); |
217 |
| - $(this).val(""); |
218 |
| - }; |
219 |
| - |
220 |
| - var pomEvents = document.getElementById('uploadEventsFile'); |
221 |
| - pomEvents.onchange = function uploadFinished() { |
222 |
| - var subscriptionFile = pomEvents.files[0]; |
223 |
| - validateJSONAndUpload(subscriptionFile, false); |
224 |
| - $(this).val(""); |
225 |
| - }; |
226 |
| - |
| 217 | + //Set onchange event on the input element "uploadRulesFile" and "uploadEventsFile" |
| 218 | + var pomRules = document.getElementById('uploadRulesFile'); |
| 219 | + pomRules.onchange = function uploadFinished() { |
| 220 | + var subscriptionFile = pomRules.files[0]; |
| 221 | + validateJSONAndUpload(subscriptionFile, true); |
| 222 | + $(this).val(""); |
| 223 | + }; |
| 224 | + |
| 225 | + var pomEvents = document.getElementById('uploadEventsFile'); |
| 226 | + pomEvents.onchange = function uploadFinished() { |
| 227 | + var subscriptionFile = pomEvents.files[0]; |
| 228 | + validateJSONAndUpload(subscriptionFile, false); |
| 229 | + $(this).val(""); |
| 230 | + }; |
| 231 | + |
227 | 232 | //Upload events list json data
|
228 | 233 | $(".container").on("click", "button.upload_rules", function(event) {
|
229 | 234 | event.stopPropagation();
|
230 | 235 | event.preventDefault();
|
| 236 | + var isRules = true; |
| 237 | + replaceAppendModal(isRules); |
231 | 238 |
|
232 |
| - function createRulesUploadWindow() { |
233 |
| - if (document.createEvent) { |
234 |
| - var event = document.createEvent('MouseEvents'); |
235 |
| - event.initEvent('click', true, true); |
236 |
| - pomRules.dispatchEvent(event); |
237 |
| - } else { |
238 |
| - pomRules.click(); |
239 |
| - } |
240 |
| - } |
241 |
| - |
242 |
| - function createUploadWindowMSExplorer() { |
243 |
| - $('#upload_rules').click(); |
244 |
| - var file = $('#upload_rules').prop('files')[0]; |
245 |
| - validateJSONAndUpload(file, true); |
246 |
| - } |
247 |
| - |
248 |
| - // HTML5 Download File window handling |
249 |
| - createRulesUploadWindow(); |
250 | 239 | });
|
251 | 240 |
|
252 |
| - //Upload list of events json data |
| 241 | + //Upload list of events json data |
253 | 242 | $(".container").on("click", "button.upload_events", function(event) {
|
254 | 243 | event.stopPropagation();
|
255 | 244 | event.preventDefault();
|
| 245 | + var isRules = false; |
| 246 | + replaceAppendModal(isRules); |
| 247 | + }); |
256 | 248 |
|
257 |
| - function createUploadWindow() { |
258 |
| - if (document.createEvent) { |
259 |
| - var event = document.createEvent('MouseEvents'); |
260 |
| - event.initEvent('click', true, true); |
261 |
| - pomEvents.dispatchEvent(event); |
262 |
| - } else { |
263 |
| - pomEvents.click(); |
264 |
| - } |
265 |
| - } |
| 249 | + function replaceAppendModal(isRules){ |
| 250 | + $('#AppendReplaceModal').modal('show'); |
266 | 251 |
|
267 |
| - function createUploadWindowMSExplorer() { |
268 |
| - $('#upload_events').click(); |
269 |
| - var file = $('#upload_events').prop('files')[0]; |
270 |
| - validateJSONAndUpload(file, false); |
271 |
| - } |
| 252 | + document.getElementById('replaceButton').onclick = function(){ |
| 253 | + $('#AppendReplaceModal').modal('hide'); |
| 254 | + isReplacing = true; |
| 255 | + if(isRules){ |
| 256 | + createRulesUploadWindow(); |
| 257 | + }else{ |
| 258 | + createUploadWindow(); |
| 259 | + } |
| 260 | + }; |
272 | 261 |
|
| 262 | + document.getElementById('appendButton').onclick = function(){ |
| 263 | + $('#AppendReplaceModal').modal('hide'); |
| 264 | + isReplacing = false; |
| 265 | + if(isRules){ |
| 266 | + createRulesUploadWindow(); |
| 267 | + }else{ |
| 268 | + createUploadWindow(); |
| 269 | + } |
| 270 | + }; |
| 271 | + } |
273 | 272 |
|
274 |
| - // HTML5 Download File window handling |
275 |
| - createUploadWindow(); |
276 |
| - }); |
| 273 | + function createRulesUploadWindow() { |
| 274 | + if (document.createEvent) { |
| 275 | + var event = document.createEvent('MouseEvents'); |
| 276 | + event.initEvent('click', true, true); |
| 277 | + pomRules.dispatchEvent(event); |
| 278 | + } else { |
| 279 | + pomRules.click(); |
| 280 | + } |
| 281 | + } |
| 282 | + |
| 283 | + function createUploadWindow() { |
| 284 | + if (document.createEvent) { |
| 285 | + var event = document.createEvent('MouseEvents'); |
| 286 | + event.initEvent('click', true, true); |
| 287 | + pomEvents.dispatchEvent(event); |
| 288 | + } else { |
| 289 | + pomEvents.click(); |
| 290 | + } |
| 291 | + } |
277 | 292 |
|
278 | 293 | // Download the modified rule
|
279 | 294 | $('.container').on('click', 'button.download_rules', function() {
|
|
0 commit comments