Built motion from commit bcd50b9.|0.0.29
[motion.git] / public / assets / plugins / square / js / Dialogs.js
1 'use strict';
2 /**
3  * $Id: Dialogs.js,v 1.5 2013-01-29 17:23:31 gaudenz Exp $
4  * Copyright (c) 2006-2012, JGraph Ltd
5  */
6 /**
7  * Constructs a new dialog.
8  */
9
10 function createCheckbox(value) {
11         var input = document.createElement('input');
12         input.setAttribute('type', 'checkbox');
13         if (value) {
14                 input.setAttribute('checked', true);
15         }
16         return input;
17 }
18
19 function createDropdownFromApi(path, value, option_name, option_value, editorUi, paginated) {
20         var req = new XMLHttpRequest();
21         req.open('GET', path, false); // `false` makes the request synchronous
22         req.setRequestHeader('Authorization', 'Bearer ' + editorUi.editor.data.token);
23         req.send(null);
24         var res = [];
25         if (req.status === 200) {
26                 res = JSON.parse(req.response);
27         }
28         var input = document.createElement('select');
29         var option = document.createElement('option');
30         option.text = '-- None --';
31         option.value = '0';
32         input.appendChild(option);
33         var selectValues = paginated ? res.rows : res;
34         selectValues.forEach(function(elem) {
35                 option = document.createElement('option');
36                 option.text = elem[option_name];
37                 option.value = elem[option_value];
38                 option.selected = (elem[option_value] == value);
39                 input.appendChild(option);
40         });
41         input.className = 'form-control select2';
42
43         return input;
44 }
45
46 function createGroupedDropdownFromApi(path, value, option_name, option_value, editorUi, paginated, associationField) {
47         var req = new XMLHttpRequest();
48         req.open('GET', path, false); // `false` makes the request synchronous
49         req.setRequestHeader('Authorization', 'Bearer ' + editorUi.editor.data.token);
50         req.send(null);
51         var res = [];
52         if (req.status === 200) {
53                 res = JSON.parse(req.response);
54         }
55         var input = document.createElement('select');
56         var option = document.createElement('option');
57         option.text = '-- None --';
58         option.value = '0';
59         input.appendChild(option);
60         var selectValues = paginated ? res.rows : res;
61         var mainFilter = {};
62         var groupFilter = {};
63         mainFilter[associationField] = null;
64         var mainValues = _.filter(selectValues, mainFilter);
65         var groupValues = {};
66         mainValues.forEach(function(elem) {
67                 option = document.createElement('option');
68                 option.className = 'select-group-father';
69                 option.text = elem[option_name].toUpperCase();
70                 option.value = elem[option_value];
71                 option.selected = (elem[option_value] == value);
72                 input.appendChild(option);
73                 groupFilter[associationField] = elem[option_value];
74                 groupValues = _.filter(selectValues, groupFilter);
75                 groupValues.forEach(function(elem) {
76                         option = document.createElement('option');
77                         option.className = 'select-group-son';
78                         option.text = '-' + _.capitalize(elem[option_name]);
79                         option.value = elem[option_value];
80                         option.selected = (elem[option_value] == value);
81                         input.appendChild(option);
82                 });
83         })
84         input.className = 'form-control select2';
85
86         return input;
87 }
88
89 function createDropdownFromArray(array, value) {
90         var input = document.createElement('select');
91
92         for (var item in array) {
93                 var option = document.createElement('option');
94                 option.text = array[item];
95                 option.value = item;
96                 if (value > 0 || value != '')
97                         option.selected = (value === item) ? true : false;
98
99                 input.appendChild(option);
100         }
101
102         input.className = 'form-control select2';
103
104         return input;
105 }
106
107 function Dialog(editorUi, elt, w, h, modal, closable, onClose) {
108         var dx = 0;
109
110         if (mxClient.IS_IE && document.documentMode != 9) {
111                 dx = 60;
112         }
113
114         w += dx;
115         h += dx;
116
117         var left = Math.max(0, Math.round((document.body.scrollWidth - w) / 2));
118         var top = Math.max(0, Math.round((Math.max(document.body.scrollHeight,
119                 document.documentElement.scrollHeight) - h) / 3));
120
121         var div = editorUi.createDiv('geDialog');
122         div.className = 'modal fade in center';
123         div.style.display = 'block';
124         div.style.paddingRight = '12px';
125         // div.style.width = w + 'px';
126         // div.style.height = h + 'px';
127         // div.style.left = left + 'px';
128         // div.style.top = top + 'px';
129
130         var divModalDialog = editorUi.createDiv('geModalDialog');
131         divModalDialog.className = 'modal-dialog';
132
133         divModalDialog.appendChild(elt);
134         div.appendChild(divModalDialog);
135
136         if (this.bg == null) {
137                 this.bg = editorUi.createDiv('background');
138                 this.bg.className = 'modal-backdrop fade in';
139
140                 if (mxClient.IS_QUIRKS) {
141                         new mxDivResizer(this.bg);
142                 }
143         }
144
145         if (modal) {
146                 document.body.appendChild(this.bg);
147         }
148
149         document.body.appendChild(div);
150
151         this.onDialogClose = onClose;
152         this.container = div;
153 };
154
155 /**
156  * Removes the dialog from the DOM.
157  */
158 Dialog.prototype.close = function() {
159         if (this.onDialogClose != null) {
160                 this.onDialogClose();
161                 this.onDialogClose = null;
162         }
163
164         this.container.parentNode.removeChild(this.container);
165         this.bg.parentNode.removeChild(this.bg);
166 };
167
168 /**
169  * Constructs a new open dialog.
170  */
171 function ImportDialog(editorUi) {
172
173         var content = editorUi.createDiv('modal-content');
174         var header = editorUi.createDiv('modal-header');
175         var body = editorUi.createDiv('modal-body');
176         var footer = editorUi.createDiv('modal-footer');
177
178         //--- START HEADER
179         var title = editorUi.createHeader('h4');
180         mxUtils.write(title, mxResources.get('import') + ' XML');
181
182         var x = mxUtils.button('', function() {
183                 editorUi.hideDialog();
184         });
185         x.className = 'close';
186
187         header.appendChild(x);
188         header.appendChild(title);
189         //--- END HEADER
190
191         //--- START BODY
192         var row = editorUi.createDiv('row');
193         var col1 = editorUi.createDiv('col-md-12');
194
195         var textarea = document.createElement('textarea');
196         textarea.style.width = '100%';
197         textarea.style.height = '374px';
198
199         var input = document.createElement('input');
200         input.type = 'file';
201         input.setAttribute('accept', 'text/xml');
202
203         input.addEventListener('change', function readSingleFile(evt) {
204                 //Retrieve the first (and only!) File from the FileList object
205                 var f = evt.target.files[0];
206                 console.log(f);
207                 if (f) {
208                         if (f.type === 'text/xml') {
209                                 var r = new FileReader();
210                                 r.onload = function(e) {
211                                         var contents = e.target.result;
212                                         mxUtils.write(textarea, contents);
213                                 };
214                                 r.readAsText(f);
215                         } else {
216                                 alert('Failed to load format file');
217                         }
218                 } else {
219                         alert('Failed to load file');
220                 }
221         }, false);
222
223         col1.appendChild(input);
224         col1.appendChild(textarea);
225
226         row.appendChild(col1);
227         body.appendChild(row);
228         //--- END BODY
229
230         //--- START FOOTER
231         var save = mxUtils.button(mxResources.get('import'), mxUtils.bind(this,
232                 function(data) {
233                         var doc = mxUtils.parseXml(textarea.value);
234                         editorUi.editor.setGraphXml(doc.documentElement);
235                         editorUi.hideDialog();
236                 }));
237         save.className = 'btn blue';
238
239         var close = mxUtils.button(mxResources.get('cancel'), function() {
240                 editorUi.hideDialog();
241         });
242         close.className = 'btn default';
243
244         footer.appendChild(save);
245         footer.appendChild(close);
246         //--- END FOOTER
247
248         //--- START CONTENT
249         content.appendChild(header);
250         content.appendChild(body);
251         content.appendChild(footer);
252         //--- END CONTENT
253
254         this.container = content;
255
256 };
257
258 /**
259  * Constructs a new about dialog.
260  */
261 function AboutDialog(editorUi) {
262         var content = editorUi.createDiv('modal-content');
263         var header = editorUi.createDiv('modal-header');
264         var body = editorUi.createDiv('modal-body');
265         var footer = editorUi.createDiv('modal-footer');
266
267         //--- START HEADER
268         var title = editorUi.createHeader('h4');
269         mxUtils.write(title, mxResources.get('about') + ' Cally Square');
270
271         var x = mxUtils.button('', function() {
272                 editorUi.hideDialog();
273         });
274         x.className = 'close';
275
276         header.appendChild(x);
277         header.appendChild(title);
278         //--- END HEADER
279
280         //--- START BODY
281         var img = document.createElement('img');
282         img.style.border = '0px';
283         img.setAttribute('width', '176');
284         img.setAttribute('width', '151');
285         img.setAttribute('src', IMAGE_PATH + '/logo.png');
286         body.appendChild(img);
287         mxUtils.br(body);
288         mxUtils.write(body, 'Powered by Xenialab ' + mxClient.VERSION);
289         mxUtils.br(body);
290         var link = document.createElement('a');
291         link.setAttribute('href', 'http://www.callysquare.com/');
292         link.setAttribute('target', '_blank');
293         mxUtils.write(link, 'www.callysquare.com');
294         body.appendChild(link);
295         mxUtils.br(body);
296         mxUtils.br(body);
297         //--- END BODY
298
299         var close = mxUtils.button(mxResources.get('close'), function() {
300                 editorUi.hideDialog();
301         });
302         close.className = 'btn default';
303
304         footer.appendChild(close);
305         //--- END FOOTER
306
307         //--- START CONTENT
308         content.appendChild(header);
309         content.appendChild(body);
310         content.appendChild(footer);
311         //--- END CONTENT
312
313         this.container = content;
314 };
315
316 /**
317  * Constructs a new save dialog.
318  */
319 function SaveDialog(editorUi) {
320
321         var content = editorUi.createDiv('modal-content');
322         var header = editorUi.createDiv('modal-header');
323         var body = editorUi.createDiv('modal-body');
324         var footer = editorUi.createDiv('modal-footer');
325
326         //--- START HEADER
327         var title = editorUi.createHeader('h4');
328         mxUtils.write(title, mxResources.get('saveAs'));
329
330         var x = mxUtils.button('', function() {
331                 editorUi.hideDialog();
332         });
333         x.className = 'close';
334
335         header.appendChild(x);
336         header.appendChild(title);
337         //--- END HEADER
338
339         //--- START BODY
340         var name = 'name';
341         var id = '_' + name;
342         var value = editorUi.editor.getOrCreateFilename();
343
344         var row = editorUi.createDiv('row');
345         var col1 = editorUi.createDiv('col-md-4');
346         var col2 = editorUi.createDiv('col-md-8');
347
348         var label = document.createElement('label');
349         label.className = 'control-label pull-right';
350         mxUtils.write(label, mxResources.get(name));
351         col1.appendChild(label);
352
353         var select = document.createElement('input');
354         select.setAttribute('value', value + '_copy');
355         select.setAttribute('id', id)
356         select.className = 'form-control';
357         col2.appendChild(select);
358
359         row.appendChild(col1);
360         row.appendChild(col2);
361         body.appendChild(row);
362         //--- END BODY
363
364         //--- START FOOTER
365         var save = mxUtils.button(mxResources.get('save'), function() {
366                 editorUi.saveAs(select.value);
367                 editorUi.hideDialog();
368         });
369         save.className = 'btn blue';
370
371         var close = mxUtils.button(mxResources.get('cancel'), function() {
372                 editorUi.hideDialog();
373         });
374         close.className = 'btn default';
375
376         footer.appendChild(save);
377         footer.appendChild(close);
378         //--- END FOOTER
379
380         //--- START CONTENT
381         content.appendChild(header);
382         content.appendChild(body);
383         content.appendChild(footer);
384         //--- END CONTENT
385
386         this.container = content;
387         //nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
388 };
389
390 /**
391  * Constructs a new save dialog.
392  */
393 function NewDialog(editorUi) {
394
395         var content = editorUi.createDiv('modal-content');
396         var header = editorUi.createDiv('modal-header');
397         var body = editorUi.createDiv('modal-body');
398         var footer = editorUi.createDiv('modal-footer');
399
400         //--- START HEADER
401         var title = editorUi.createHeader('h4');
402         mxUtils.write(title, mxResources.get('new'));
403
404         var x = mxUtils.button('', function() {
405                 editorUi.hideDialog();
406         });
407         x.className = 'close';
408
409         header.appendChild(x);
410         header.appendChild(title);
411         //--- END HEADER
412
413         //--- START BODY
414         var name = 'name';
415         var id = '_' + name;
416         var value = editorUi.editor.getOrCreateFilename();
417
418         var row = editorUi.createDiv('row');
419         var col1 = editorUi.createDiv('col-md-4');
420         var col2 = editorUi.createDiv('col-md-8');
421
422         var label = document.createElement('label');
423         label.className = 'control-label pull-right';
424         mxUtils.write(label, mxResources.get(name));
425         col1.appendChild(label);
426
427         var select = document.createElement('input');
428         select.setAttribute('value', value + '_new');
429         select.setAttribute('id', id)
430         select.className = 'form-control';
431         col2.appendChild(select);
432
433         row.appendChild(col1);
434         row.appendChild(col2);
435         body.appendChild(row);
436         //--- END BODY
437
438         //--- START FOOTER
439         var save = mxUtils.button(mxResources.get('new'), function() {
440                 editorUi.new(select.value);
441                 editorUi.hideDialog();
442         });
443         save.className = 'btn blue';
444
445         var close = mxUtils.button(mxResources.get('cancel'), function() {
446                 editorUi.hideDialog();
447         });
448         close.className = 'btn default';
449
450         footer.appendChild(save);
451         footer.appendChild(close);
452         //--- END FOOTER
453
454         //--- START CONTENT
455         content.appendChild(header);
456         content.appendChild(body);
457         content.appendChild(footer);
458         //--- END CONTENT
459
460         this.container = content;
461         //nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
462 };
463
464 /**
465  * Constructs a new save dialog.
466  */
467 function VariableDialog(editorUi) {
468
469         var content = editorUi.createDiv('modal-content');
470         var header = editorUi.createDiv('modal-header');
471         var body = editorUi.createDiv('modal-body');
472         var footer = editorUi.createDiv('modal-footer');
473
474         //--- START HEADER
475         var title = editorUi.createHeader('h4');
476         mxUtils.write(title, mxResources.get('variable'));
477
478         var x = mxUtils.button('', function() {
479                 editorUi.hideDialog();
480         });
481         x.className = 'close';
482
483         header.appendChild(x);
484         header.appendChild(title);
485         //--- END HEADER
486
487         //--- START BODY
488         var name = 'name';
489         var id = '_' + name;
490         var value = editorUi.editor.getOrCreateFilename();
491
492         var row = editorUi.createDiv('row');
493         var col1 = editorUi.createDiv('col-md-4');
494         var col2 = editorUi.createDiv('col-md-8');
495
496         var label = document.createElement('label');
497         label.className = 'control-label pull-right';
498         mxUtils.write(label, mxResources.get(name));
499         col1.appendChild(label);
500
501         var select = document.createElement('input');
502         select.setAttribute('value', 'variable name');
503         select.setAttribute('id', id)
504         select.className = 'form-control';
505         col2.appendChild(select);
506
507         row.appendChild(col1);
508         row.appendChild(col2);
509         body.appendChild(row);
510         //--- END BODY
511
512         //--- START FOOTER
513         var save = mxUtils.button(mxResources.get('new'), function() {
514                 editorUi.variable(select.value);
515                 editorUi.hideDialog();
516         });
517         save.className = 'btn blue';
518
519         var close = mxUtils.button(mxResources.get('cancel'), function() {
520                 editorUi.hideDialog();
521         });
522         close.className = 'btn default';
523
524         footer.appendChild(save);
525         footer.appendChild(close);
526         //--- END FOOTER
527
528         //--- START CONTENT
529         content.appendChild(header);
530         content.appendChild(body);
531         content.appendChild(footer);
532         //--- END CONTENT
533
534         this.container = content;
535         //nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
536 };
537
538 /**
539  * Constructs a new save dialog.
540  */
541 function OpenDialog(editorUi) {
542
543         var content = editorUi.createDiv('modal-content');
544         var header = editorUi.createDiv('modal-header');
545         var body = editorUi.createDiv('modal-body');
546         var footer = editorUi.createDiv('modal-footer');
547
548         //--- START HEADER
549         var title = editorUi.createHeader('h4');
550         mxUtils.write(title, mxResources.get('open'));
551
552         var x = mxUtils.button('', function() {
553                 editorUi.hideDialog();
554         });
555         x.className = 'close';
556
557         header.appendChild(x);
558         header.appendChild(title);
559         //--- END HEADER
560
561         //--- START BODY
562         var row = editorUi.createDiv('row');
563         var col1 = editorUi.createDiv('col-md-4');
564         var col2 = editorUi.createDiv('col-md-8');
565
566         var label = document.createElement('label');
567         label.className = 'control-label pull-right';
568         mxUtils.write(label, mxResources.get('name'));
569         col1.appendChild(label);
570
571         var req = new XMLHttpRequest();
572         req.open('GET', '/api/square/projects', false); // `false` makes the request synchronous
573         req.setRequestHeader('Authorization', 'Bearer ' + editorUi.editor.data.token);
574         req.send(null);
575         var res = [];
576         if (req.status === 200) {
577                 res = JSON.parse(req.response);
578         }
579
580         var select = document.createElement('select');
581
582         for (var j = 0; j < res.length; j++) {
583                 var option = document.createElement('option');
584                 option.text = res[j].name;
585                 option.value = res[j].id;
586                 select.appendChild(option);
587         }
588         select.className = 'form-control';
589         col2.appendChild(select);
590
591         row.appendChild(col1);
592         row.appendChild(col2);
593         body.appendChild(row);
594         //--- END BODY
595
596         //--- START FOOTER
597         var save = mxUtils.button(mxResources.get('open'), function() {
598                 console.log(select);
599                 console.log(select.value);
600                 window.open('square/project/' + select.value, '_blank');
601                 editorUi.hideDialog();
602         });
603         save.className = 'btn blue';
604
605         var close = mxUtils.button(mxResources.get('cancel'), function() {
606                 editorUi.hideDialog();
607         });
608         close.className = 'btn default';
609
610         footer.appendChild(save);
611         footer.appendChild(close);
612         //--- END FOOTER
613
614         //--- START CONTENT
615         content.appendChild(header);
616         content.appendChild(body);
617         content.appendChild(footer);
618         //--- END CONTENT
619
620         this.container = content;
621         //nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
622 };
623
624
625 /**
626  * Constructs a new edit file dialog.
627  */
628 function EditFileDialog(editorUi) {
629
630         var content = editorUi.createDiv('modal-content');
631         var header = editorUi.createDiv('modal-header');
632         var body = editorUi.createDiv('modal-body');
633         var footer = editorUi.createDiv('modal-footer');
634
635         //--- START HEADER
636         var title = editorUi.createHeader('h4');
637         mxUtils.write(title, mxResources.get('edit'));
638
639         var x = mxUtils.button('', function() {
640                 editorUi.hideDialog();
641         });
642         x.className = 'close';
643
644         header.appendChild(x);
645         header.appendChild(title);
646         //--- END HEADER
647
648         //--- START BODY
649         var row = editorUi.createDiv('row');
650         var col1 = editorUi.createDiv('col-md-12');
651
652         var textarea = document.createElement('textarea');
653         textarea.style.width = '100%';
654         textarea.style.height = '374px';
655         textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
656
657         // Enables dropping files
658         if (fileSupport) {
659                 function handleDrop(evt) {
660                         evt.stopPropagation();
661                         evt.preventDefault();
662
663                         if (evt.dataTransfer.files.length > 0) {
664                                 var file = evt.dataTransfer.files[0];
665
666                                 var reader = new FileReader();
667                                 reader.onload = function(e) {
668                                         textarea.value = e.target.result;
669                                 };
670                                 reader.readAsText(file);
671                         }
672                 };
673
674                 function handleDragOver(evt) {
675                         evt.stopPropagation();
676                         evt.preventDefault();
677                 };
678
679                 // Setup the dnd listeners.
680                 textarea.addEventListener('dragover', handleDragOver, false);
681                 textarea.addEventListener('drop', handleDrop, false);
682         }
683         col1.appendChild(textarea);
684
685         row.appendChild(col1);
686         body.appendChild(row);
687         //--- END BODY
688
689         //--- START FOOTER
690         var save = mxUtils.button(mxResources.get('save'), function() {
691                 var doc = mxUtils.parseXml(textarea.value);
692                 editorUi.editor.setGraphXml(doc.documentElement);
693                 editorUi.hideDialog();
694         });
695         save.className = 'btn blue';
696
697         var close = mxUtils.button(mxResources.get('cancel'), function() {
698                 editorUi.hideDialog();
699         });
700         close.className = 'btn default';
701
702         footer.appendChild(save);
703         footer.appendChild(close);
704         //--- END FOOTER
705
706         //--- START CONTENT
707         content.appendChild(header);
708         content.appendChild(body);
709         content.appendChild(footer);
710         //--- END CONTENT
711
712         this.container = content;
713 };
714
715 /**
716  * Constructs a new export dialog.
717  */
718 function ExportDialog(editorUi) {
719         var content = editorUi.createDiv('modal-content');
720         var header = editorUi.createDiv('modal-header');
721         var body = editorUi.createDiv('modal-body form');
722         var footer = editorUi.createDiv('modal-footer');
723
724         //--- START HEADER
725         var title = editorUi.createHeader('h4');
726         mxUtils.write(title, mxResources.get('export') + ' XML');
727
728         var x = mxUtils.button('', function() {
729                 editorUi.hideDialog();
730         });
731         x.className = 'close';
732
733         header.appendChild(x);
734         header.appendChild(title);
735         //--- END HEADER
736
737         //--- START BODY
738         var form = editorUi.createDiv('form-horizontal form-row-seperated');
739         var group = editorUi.createDiv('form-group last');
740
741         var label = document.createElement('label');
742         label.className = 'col-sm-4 control-label';
743         mxUtils.write(label, mxResources.get('filename'));
744
745         var input = document.createElement('input');
746         input.setAttribute('value', editorUi.editor.getOrCreateFilename());
747         input.className = 'form-control';
748
749         var div = editorUi.createDiv('col-sm-8');
750         div.appendChild(input);
751
752         group.appendChild(label);
753         group.appendChild(div);
754         form.appendChild(group);
755
756         body.appendChild(form);
757         //--- END BODY
758
759         //--- START FOOTER
760         var save = mxUtils.button(mxResources.get('export'), mxUtils.bind(this,
761                 function(data) {
762                         editorUi.save(false);
763
764                         var xml = encodeURIComponent(mxUtils.getXml(editorUi.editor.getGraphXml()));
765                         new mxXmlRequest(SAVE_URL + editorUi.editor.data.id + '/download',
766                                 'filename=' + input.value, 'GET').simulate(document, "_blank");
767                         editorUi.hideDialog();
768                 }));
769         save.className = 'btn blue';
770
771         var close = mxUtils.button(mxResources.get('cancel'), function() {
772                 editorUi.hideDialog();
773         });
774         close.className = 'btn default';
775
776         footer.appendChild(save);
777         footer.appendChild(close);
778         //--- END FOOTER
779
780         //--- START CONTENT
781         content.appendChild(header);
782         content.appendChild(body);
783         content.appendChild(footer);
784         //--- END CONTENT
785
786         this.container = content;
787 };
788
789 /**
790  * Giuseppe Careri
791  * Constructs a new general dialog.
792  */
793 function GeneralDialog(editorUi, cell) {
794         var graph = editorUi.editor.graph;
795
796         var content = editorUi.createDiv('modal-content');
797         var header = editorUi.createDiv('modal-header');
798         var body = editorUi.createDiv('modal-body form modal-body-scroll');
799         var footer = editorUi.createDiv('modal-footer');
800
801         //--- START HEADER
802         var title = editorUi.createHeader('h4');
803         mxUtils.write(title, mxResources.get('edit') + ' ' + mxResources.get(cell.value
804                 .nodeName));
805
806         var x = mxUtils.button('', function() {
807                 editorUi.hideDialog();
808         });
809         x.className = 'close';
810
811         header.appendChild(x);
812         header.appendChild(title);
813         //--- END HEADER
814
815         //--- START BODY
816         var length = cell.value.attributes.length;
817         var form = editorUi.createDiv('form-horizontal form-row-seperated');
818
819         for (var i = 0; i < length; i++) {
820                 var name = cell.value.attributes[i].name;
821                 var id = '_' + name;
822                 var value = cell.value.attributes[i].value;
823
824                 var group = editorUi.createDiv((i == length - 1) ? 'form-group last' :
825                         'form-group');
826
827                 var label = document.createElement('label');
828                 label.className = 'col-sm-4 control-label';
829                 mxUtils.write(label, mxResources.get(name));
830                 group.appendChild(label);
831
832                 var input;
833
834                 switch (name) {
835                         case 'sip_id':
836                                 input = createDropdownFromApi('/api/agents', value, 'name', 'id', editorUi, true);
837                                 break;
838                         case 'queue_id':
839                                 input = createDropdownFromApi('/api/voice/queues', value, 'name', 'name', editorUi, true);
840                                 break;
841                         case 'trunk_id':
842                                 input = createDropdownFromApi('/api/trunks', value, 'name', 'id', editorUi, true);
843                                 break;
844                         case 'variable_id':
845                                 input = createDropdownFromApi('/api/square/variables', value, 'name', 'id', editorUi, true); //mettere true dopo la pagination
846                                 break;
847                         case 'model':
848                                 input = createDropdownFromArray(ISPEECHASRMODEL, value);
849                                 break;
850                         case 'ispeech_asr_language':
851                                 input = createDropdownFromArray(ISPEECHASRLANG, value);
852                                 break;
853                         case 'ispeech_tts_language':
854                                 input = createDropdownFromArray(ISPEECHLANG, value);
855                                 break;
856                         case 'google_tts_language':
857                                 input = createDropdownFromArray(GOOGLETTSLANG, value);
858                                 break;
859                         case 'interval_id':
860                                 input = createGroupedDropdownFromApi('/api/intervals/all', value, 'name', 'id', editorUi, false, 'IntervalId');
861                                 break;
862                         case 'project_id':
863                                 input = createDropdownFromApi('/api/square/projects', value, 'name', 'id', editorUi, true);
864                                 break;
865                         case 'odbc_id':
866                                 input = createDropdownFromApi('/api/square/odbc', value, 'name', 'id', editorUi, true);
867                                 break;
868                         case 'file_id':
869                                 input = createDropdownFromApi('/api/uploads', value, 'display_name', 'id', editorUi, false);
870                                 break;
871                         case 'timeout':
872                         case 'digit':
873                         case 'mindigit':
874                         case 'maxdigit':
875                         case 'response':
876                         case 'retry':
877                                 input = document.createElement('input');
878                                 input.setAttribute('type', 'number');
879                                 input.setAttribute('min', 0);
880                                 input.setAttribute('max', 1000);
881                                 input.setAttribute('value', value);
882                                 input.className = 'form-control';
883                                 break;
884                         case 'text':
885                         case 'key':
886                         case 'query':
887                         case 'condition':
888                         case 'command':
889                                 input = document.createElement('textarea');
890                                 input.innerHTML = value;
891                                 input.className = 'form-control';
892                                 break;
893                         default:
894                                 input = document.createElement('input');
895                                 input.setAttribute('value', value);
896                                 input.className = 'form-control';
897                                 break;
898                 }
899
900                 input.setAttribute('id', id)
901
902                 var div = editorUi.createDiv('col-sm-8');
903                 div.appendChild(input);
904
905                 // Help
906                 if (mxResources.get('help_' + name)) {
907                         var help = editorUi.createDiv('p');
908                         help.className = 'help-block';
909                         mxUtils.write(help, mxResources.get('help_' + name));
910                         div.appendChild(help);
911                 }
912
913                 group.appendChild(div);
914                 form.appendChild(group);
915         }
916         body.appendChild(form);
917         //--- END BODY
918
919         //--- START FOOTER
920         var save = mxUtils.button(mxResources.get('save'), mxUtils.bind(this,
921                 function(data) {
922                         for (var i = 0; i < cell.value.attributes.length; i++) {
923                                 var id = '_' + cell.value.attributes[i].name;
924                                 var name = cell.value.attributes[i].name;
925                                 console.log(name, document.getElementById(id).value);
926                                 cell.setAttribute(name, document.getElementById(id).value);
927                         };
928                         graph.refresh(cell);
929                         editorUi.hideDialog();
930                 }));
931         save.className = 'btn blue';
932
933         var close = mxUtils.button(mxResources.get('cancel'), function() {
934                 editorUi.hideDialog();
935         });
936         close.className = 'btn default';
937
938         footer.appendChild(save);
939         footer.appendChild(close);
940         //--- END FOOTER
941
942         //--- START CONTENT
943         content.appendChild(header);
944         content.appendChild(body);
945         content.appendChild(footer);
946         //--- END CONTENT
947
948         this.container = content;
949 };