Dialogs.js 62 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558
  1. /**
  2. * Copyright (c) 2006-2012, JGraph Ltd
  3. */
  4. /**
  5. * Constructs a new open dialog.
  6. */
  7. var OpenDialog = function()
  8. {
  9. var iframe = document.createElement('iframe');
  10. iframe.style.backgroundColor = 'transparent';
  11. iframe.allowTransparency = 'true';
  12. iframe.style.borderStyle = 'none';
  13. iframe.style.borderWidth = '0px';
  14. iframe.style.overflow = 'hidden';
  15. iframe.frameBorder = '0';
  16. // Adds padding as a workaround for box model in older IE versions
  17. var dx = (mxClient.IS_VML && (document.documentMode == null || document.documentMode < 8)) ? 20 : 0;
  18. iframe.setAttribute('width', (((Editor.useLocalStorage) ? 640 : 320) + dx) + 'px');
  19. iframe.setAttribute('height', (((Editor.useLocalStorage) ? 480 : 220) + dx) + 'px');
  20. iframe.setAttribute('src', OPEN_FORM);
  21. this.container = iframe;
  22. };
  23. /**
  24. * Constructs a new color dialog.
  25. */
  26. var ColorDialog = function(editorUi, color, apply, cancelFn)
  27. {
  28. this.editorUi = editorUi;
  29. var input = document.createElement('input');
  30. input.style.marginBottom = '10px';
  31. input.style.width = '216px';
  32. // Required for picker to render in IE
  33. if (mxClient.IS_IE)
  34. {
  35. input.style.marginTop = '10px';
  36. document.body.appendChild(input);
  37. }
  38. var applyFunction = (apply != null) ? apply : this.createApplyFunction();
  39. function doApply()
  40. {
  41. var color = input.value;
  42. // Blocks any non-alphabetic chars in colors
  43. if (/(^#?[a-zA-Z0-9]*$)/.test(color))
  44. {
  45. if (color != 'none' && color.charAt(0) != '#')
  46. {
  47. color = '#' + color;
  48. }
  49. ColorDialog.addRecentColor((color != 'none') ? color.substring(1) : color, 12);
  50. applyFunction(color);
  51. editorUi.hideDialog();
  52. }
  53. else
  54. {
  55. editorUi.handleError({message: mxResources.get('invalidInput')});
  56. }
  57. };
  58. this.init = function()
  59. {
  60. if (!mxClient.IS_TOUCH)
  61. {
  62. input.focus();
  63. }
  64. };
  65. var picker = new mxJSColor.color(input);
  66. picker.pickerOnfocus = false;
  67. picker.showPicker();
  68. var div = document.createElement('div');
  69. mxJSColor.picker.box.style.position = 'relative';
  70. mxJSColor.picker.box.style.width = '230px';
  71. mxJSColor.picker.box.style.height = '100px';
  72. mxJSColor.picker.box.style.paddingBottom = '10px';
  73. div.appendChild(mxJSColor.picker.box);
  74. var center = document.createElement('center');
  75. function createRecentColorTable()
  76. {
  77. var table = addPresets((ColorDialog.recentColors.length == 0) ? ['FFFFFF'] :
  78. ColorDialog.recentColors, 11, 'FFFFFF', true);
  79. table.style.marginBottom = '8px';
  80. return table;
  81. };
  82. function addPresets(presets, rowLength, defaultColor, addResetOption)
  83. {
  84. rowLength = (rowLength != null) ? rowLength : 12;
  85. var table = document.createElement('table');
  86. table.style.borderCollapse = 'collapse';
  87. table.setAttribute('cellspacing', '0');
  88. table.style.marginBottom = '20px';
  89. table.style.cellSpacing = '0px';
  90. var tbody = document.createElement('tbody');
  91. table.appendChild(tbody);
  92. var rows = presets.length / rowLength;
  93. for (var row = 0; row < rows; row++)
  94. {
  95. var tr = document.createElement('tr');
  96. for (var i = 0; i < rowLength; i++)
  97. {
  98. (function(clr)
  99. {
  100. var td = document.createElement('td');
  101. td.style.border = '1px solid black';
  102. td.style.padding = '0px';
  103. td.style.width = '16px';
  104. td.style.height = '16px';
  105. if (clr == null)
  106. {
  107. clr = defaultColor;
  108. }
  109. if (clr == 'none')
  110. {
  111. td.style.background = 'url(\'' + Dialog.prototype.noColorImage + '\')';
  112. }
  113. else
  114. {
  115. td.style.backgroundColor = '#' + clr;
  116. }
  117. tr.appendChild(td);
  118. if (clr != null)
  119. {
  120. td.style.cursor = 'pointer';
  121. mxEvent.addListener(td, 'click', function()
  122. {
  123. if (clr == 'none')
  124. {
  125. picker.fromString('ffffff');
  126. input.value = 'none';
  127. }
  128. else
  129. {
  130. picker.fromString(clr);
  131. }
  132. });
  133. mxEvent.addListener(td, 'dblclick', doApply);
  134. }
  135. })(presets[row * rowLength + i]);
  136. }
  137. tbody.appendChild(tr);
  138. }
  139. if (addResetOption)
  140. {
  141. var td = document.createElement('td');
  142. td.setAttribute('title', mxResources.get('reset'));
  143. td.style.border = '1px solid black';
  144. td.style.padding = '0px';
  145. td.style.width = '16px';
  146. td.style.height = '16px';
  147. td.style.backgroundImage = 'url(\'' + Dialog.prototype.closeImage + '\')';
  148. td.style.backgroundPosition = 'center center';
  149. td.style.backgroundRepeat = 'no-repeat';
  150. td.style.cursor = 'pointer';
  151. tr.appendChild(td);
  152. mxEvent.addListener(td, 'click', function()
  153. {
  154. ColorDialog.resetRecentColors();
  155. table.parentNode.replaceChild(createRecentColorTable(), table);
  156. });
  157. }
  158. center.appendChild(table);
  159. return table;
  160. };
  161. div.appendChild(input);
  162. mxUtils.br(div);
  163. // Adds recent colors
  164. createRecentColorTable();
  165. // Adds presets
  166. var table = addPresets(this.presetColors);
  167. table.style.marginBottom = '8px';
  168. table = addPresets(this.defaultColors);
  169. table.style.marginBottom = '16px';
  170. div.appendChild(center);
  171. var buttons = document.createElement('div');
  172. buttons.style.textAlign = 'right';
  173. buttons.style.whiteSpace = 'nowrap';
  174. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  175. {
  176. editorUi.hideDialog();
  177. if (cancelFn != null)
  178. {
  179. cancelFn();
  180. }
  181. });
  182. cancelBtn.className = 'geBtn';
  183. if (editorUi.editor.cancelFirst)
  184. {
  185. buttons.appendChild(cancelBtn);
  186. }
  187. var applyBtn = mxUtils.button(mxResources.get('apply'), doApply);
  188. applyBtn.className = 'geBtn gePrimaryBtn';
  189. buttons.appendChild(applyBtn);
  190. if (!editorUi.editor.cancelFirst)
  191. {
  192. buttons.appendChild(cancelBtn);
  193. }
  194. if (color != null)
  195. {
  196. if (color == 'none')
  197. {
  198. picker.fromString('ffffff');
  199. input.value = 'none';
  200. }
  201. else
  202. {
  203. picker.fromString(color);
  204. }
  205. }
  206. div.appendChild(buttons);
  207. this.picker = picker;
  208. this.colorInput = input;
  209. // LATER: Only fires if input if focused, should always
  210. // fire if this dialog is showing.
  211. mxEvent.addListener(div, 'keydown', function(e)
  212. {
  213. if (e.keyCode == 27)
  214. {
  215. editorUi.hideDialog();
  216. if (cancelFn != null)
  217. {
  218. cancelFn();
  219. }
  220. mxEvent.consume(e);
  221. }
  222. });
  223. this.container = div;
  224. };
  225. /**
  226. * Creates function to apply value
  227. */
  228. ColorDialog.prototype.presetColors = ['E6D0DE', 'CDA2BE', 'B5739D', 'E1D5E7', 'C3ABD0', 'A680B8', 'D4E1F5', 'A9C4EB', '7EA6E0', 'D5E8D4', '9AC7BF', '67AB9F', 'D5E8D4', 'B9E0A5', '97D077', 'FFF2CC', 'FFE599', 'FFD966', 'FFF4C3', 'FFCE9F', 'FFB570', 'F8CECC', 'F19C99', 'EA6B66'];
  229. /**
  230. * Creates function to apply value
  231. */
  232. ColorDialog.prototype.defaultColors = ['none', 'FFFFFF', 'E6E6E6', 'CCCCCC', 'B3B3B3', '999999', '808080', '666666', '4D4D4D', '333333', '1A1A1A', '000000', 'FFCCCC', 'FFE6CC', 'FFFFCC', 'E6FFCC', 'CCFFCC', 'CCFFE6', 'CCFFFF', 'CCE5FF', 'CCCCFF', 'E5CCFF', 'FFCCFF', 'FFCCE6',
  233. 'FF9999', 'FFCC99', 'FFFF99', 'CCFF99', '99FF99', '99FFCC', '99FFFF', '99CCFF', '9999FF', 'CC99FF', 'FF99FF', 'FF99CC', 'FF6666', 'FFB366', 'FFFF66', 'B3FF66', '66FF66', '66FFB3', '66FFFF', '66B2FF', '6666FF', 'B266FF', 'FF66FF', 'FF66B3', 'FF3333', 'FF9933', 'FFFF33',
  234. '99FF33', '33FF33', '33FF99', '33FFFF', '3399FF', '3333FF', '9933FF', 'FF33FF', 'FF3399', 'FF0000', 'FF8000', 'FFFF00', '80FF00', '00FF00', '00FF80', '00FFFF', '007FFF', '0000FF', '7F00FF', 'FF00FF', 'FF0080', 'CC0000', 'CC6600', 'CCCC00', '66CC00', '00CC00', '00CC66',
  235. '00CCCC', '0066CC', '0000CC', '6600CC', 'CC00CC', 'CC0066', '990000', '994C00', '999900', '4D9900', '009900', '00994D', '009999', '004C99', '000099', '4C0099', '990099', '99004D', '660000', '663300', '666600', '336600', '006600', '006633', '006666', '003366', '000066',
  236. '330066', '660066', '660033', '330000', '331A00', '333300', '1A3300', '003300', '00331A', '003333', '001933', '000033', '190033', '330033', '33001A'];
  237. /**
  238. * Creates function to apply value
  239. */
  240. ColorDialog.prototype.createApplyFunction = function()
  241. {
  242. return mxUtils.bind(this, function(color)
  243. {
  244. var graph = this.editorUi.editor.graph;
  245. graph.getModel().beginUpdate();
  246. try
  247. {
  248. graph.setCellStyles(this.currentColorKey, color);
  249. this.editorUi.fireEvent(new mxEventObject('styleChanged', 'keys', [this.currentColorKey],
  250. 'values', [color], 'cells', graph.getSelectionCells()));
  251. }
  252. finally
  253. {
  254. graph.getModel().endUpdate();
  255. }
  256. });
  257. };
  258. /**
  259. *
  260. */
  261. ColorDialog.recentColors = [];
  262. /**
  263. * Adds recent color for later use.
  264. */
  265. ColorDialog.addRecentColor = function(color, max)
  266. {
  267. if (color != null)
  268. {
  269. mxUtils.remove(color, ColorDialog.recentColors);
  270. ColorDialog.recentColors.splice(0, 0, color);
  271. if (ColorDialog.recentColors.length >= max)
  272. {
  273. ColorDialog.recentColors.pop();
  274. }
  275. }
  276. };
  277. /**
  278. * Adds recent color for later use.
  279. */
  280. ColorDialog.resetRecentColors = function()
  281. {
  282. ColorDialog.recentColors = [];
  283. };
  284. /**
  285. * Constructs a new about dialog.
  286. */
  287. var AboutDialog = function(editorUi)
  288. {
  289. var div = document.createElement('div');
  290. div.setAttribute('align', 'center');
  291. var h3 = document.createElement('h3');
  292. mxUtils.write(h3, mxResources.get('about') + ' GraphEditor');
  293. div.appendChild(h3);
  294. var img = document.createElement('img');
  295. img.style.border = '0px';
  296. img.setAttribute('width', '176');
  297. img.setAttribute('width', '151');
  298. img.setAttribute('src', IMAGE_PATH + '/logo.png');
  299. div.appendChild(img);
  300. mxUtils.br(div);
  301. mxUtils.write(div, 'Powered by mxGraph ' + mxClient.VERSION);
  302. mxUtils.br(div);
  303. var link = document.createElement('a');
  304. link.setAttribute('href', 'http://www.jgraph.com/');
  305. link.setAttribute('target', '_blank');
  306. mxUtils.write(link, 'www.jgraph.com');
  307. div.appendChild(link);
  308. mxUtils.br(div);
  309. mxUtils.br(div);
  310. var closeBtn = mxUtils.button(mxResources.get('close'), function()
  311. {
  312. editorUi.hideDialog();
  313. });
  314. closeBtn.className = 'geBtn gePrimaryBtn';
  315. div.appendChild(closeBtn);
  316. this.container = div;
  317. };
  318. /**
  319. * Constructs a new textarea dialog.
  320. */
  321. var TextareaDialog = function(editorUi, title, url, fn, cancelFn, cancelTitle, w, h,
  322. addButtons, noHide, noWrap, applyTitle, helpLink, customButtons)
  323. {
  324. w = (w != null) ? w : 300;
  325. h = (h != null) ? h : 120;
  326. noHide = (noHide != null) ? noHide : false;
  327. var row, td;
  328. var table = document.createElement('table');
  329. var tbody = document.createElement('tbody');
  330. row = document.createElement('tr');
  331. td = document.createElement('td');
  332. td.style.fontSize = '10pt';
  333. td.style.width = '100px';
  334. mxUtils.write(td, title);
  335. row.appendChild(td);
  336. tbody.appendChild(row);
  337. row = document.createElement('tr');
  338. td = document.createElement('td');
  339. var nameInput = document.createElement('textarea');
  340. if (noWrap)
  341. {
  342. nameInput.setAttribute('wrap', 'off');
  343. }
  344. nameInput.setAttribute('spellcheck', 'false');
  345. nameInput.setAttribute('autocorrect', 'off');
  346. nameInput.setAttribute('autocomplete', 'off');
  347. nameInput.setAttribute('autocapitalize', 'off');
  348. mxUtils.write(nameInput, url || '');
  349. nameInput.style.resize = 'none';
  350. nameInput.style.width = w + 'px';
  351. nameInput.style.height = h + 'px';
  352. this.textarea = nameInput;
  353. this.init = function()
  354. {
  355. nameInput.focus();
  356. nameInput.scrollTop = 0;
  357. };
  358. td.appendChild(nameInput);
  359. row.appendChild(td);
  360. tbody.appendChild(row);
  361. row = document.createElement('tr');
  362. td = document.createElement('td');
  363. td.style.paddingTop = '14px';
  364. td.style.whiteSpace = 'nowrap';
  365. td.setAttribute('align', 'right');
  366. if (helpLink != null)
  367. {
  368. var helpBtn = mxUtils.button(mxResources.get('help'), function()
  369. {
  370. editorUi.editor.graph.openLink(helpLink);
  371. });
  372. helpBtn.className = 'geBtn';
  373. td.appendChild(helpBtn);
  374. }
  375. if (customButtons != null)
  376. {
  377. for (var i = 0; i < customButtons.length; i++)
  378. {
  379. (function(label, fn)
  380. {
  381. var customBtn = mxUtils.button(label, function(e)
  382. {
  383. fn(e, nameInput);
  384. });
  385. customBtn.className = 'geBtn';
  386. td.appendChild(customBtn);
  387. })(customButtons[i][0], customButtons[i][1]);
  388. }
  389. }
  390. var cancelBtn = mxUtils.button(cancelTitle || mxResources.get('cancel'), function()
  391. {
  392. editorUi.hideDialog();
  393. if (cancelFn != null)
  394. {
  395. cancelFn();
  396. }
  397. });
  398. cancelBtn.className = 'geBtn';
  399. if (editorUi.editor.cancelFirst)
  400. {
  401. td.appendChild(cancelBtn);
  402. }
  403. if (addButtons != null)
  404. {
  405. addButtons(td, nameInput);
  406. }
  407. if (fn != null)
  408. {
  409. var genericBtn = mxUtils.button(applyTitle || mxResources.get('apply'), function()
  410. {
  411. if (!noHide)
  412. {
  413. editorUi.hideDialog();
  414. }
  415. fn(nameInput.value);
  416. });
  417. genericBtn.className = 'geBtn gePrimaryBtn';
  418. td.appendChild(genericBtn);
  419. }
  420. if (!editorUi.editor.cancelFirst)
  421. {
  422. td.appendChild(cancelBtn);
  423. }
  424. row.appendChild(td);
  425. tbody.appendChild(row);
  426. table.appendChild(tbody);
  427. this.container = table;
  428. };
  429. /**
  430. * Constructs a new edit file dialog.
  431. */
  432. var EditDiagramDialog = function(editorUi)
  433. {
  434. var div = document.createElement('div');
  435. div.style.textAlign = 'right';
  436. var textarea = document.createElement('textarea');
  437. textarea.setAttribute('wrap', 'off');
  438. textarea.setAttribute('spellcheck', 'false');
  439. textarea.setAttribute('autocorrect', 'off');
  440. textarea.setAttribute('autocomplete', 'off');
  441. textarea.setAttribute('autocapitalize', 'off');
  442. textarea.style.overflow = 'auto';
  443. textarea.style.resize = 'none';
  444. textarea.style.width = '600px';
  445. textarea.style.height = '360px';
  446. textarea.style.marginBottom = '16px';
  447. textarea.value = mxUtils.getPrettyXml(editorUi.editor.getGraphXml());
  448. div.appendChild(textarea);
  449. this.init = function()
  450. {
  451. textarea.focus();
  452. };
  453. // Enables dropping files
  454. if (Graph.fileSupport)
  455. {
  456. function handleDrop(evt)
  457. {
  458. evt.stopPropagation();
  459. evt.preventDefault();
  460. if (evt.dataTransfer.files.length > 0)
  461. {
  462. var file = evt.dataTransfer.files[0];
  463. var reader = new FileReader();
  464. reader.onload = function(e)
  465. {
  466. textarea.value = e.target.result;
  467. };
  468. reader.readAsText(file);
  469. }
  470. else
  471. {
  472. textarea.value = editorUi.extractGraphModelFromEvent(evt);
  473. }
  474. };
  475. function handleDragOver(evt)
  476. {
  477. evt.stopPropagation();
  478. evt.preventDefault();
  479. };
  480. // Setup the dnd listeners.
  481. textarea.addEventListener('dragover', handleDragOver, false);
  482. textarea.addEventListener('drop', handleDrop, false);
  483. }
  484. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  485. {
  486. editorUi.hideDialog();
  487. });
  488. cancelBtn.className = 'geBtn';
  489. if (editorUi.editor.cancelFirst)
  490. {
  491. div.appendChild(cancelBtn);
  492. }
  493. var select = document.createElement('select');
  494. select.style.width = '180px';
  495. select.className = 'geBtn';
  496. if (editorUi.editor.graph.isEnabled())
  497. {
  498. var replaceOption = document.createElement('option');
  499. replaceOption.setAttribute('value', 'replace');
  500. mxUtils.write(replaceOption, mxResources.get('replaceExistingDrawing'));
  501. select.appendChild(replaceOption);
  502. }
  503. var newOption = document.createElement('option');
  504. newOption.setAttribute('value', 'new');
  505. mxUtils.write(newOption, mxResources.get('openInNewWindow'));
  506. if (EditDiagramDialog.showNewWindowOption)
  507. {
  508. select.appendChild(newOption);
  509. }
  510. if (editorUi.editor.graph.isEnabled())
  511. {
  512. var importOption = document.createElement('option');
  513. importOption.setAttribute('value', 'import');
  514. mxUtils.write(importOption, mxResources.get('addToExistingDrawing'));
  515. select.appendChild(importOption);
  516. }
  517. div.appendChild(select);
  518. var okBtn = mxUtils.button(mxResources.get('ok'), function()
  519. {
  520. // Removes all illegal control characters before parsing
  521. var data = Graph.zapGremlins(mxUtils.trim(textarea.value));
  522. var error = null;
  523. if (select.value == 'new')
  524. {
  525. editorUi.hideDialog();
  526. editorUi.editor.editAsNew(data);
  527. }
  528. else if (select.value == 'replace')
  529. {
  530. editorUi.editor.graph.model.beginUpdate();
  531. try
  532. {
  533. editorUi.editor.setGraphXml(mxUtils.parseXml(data).documentElement);
  534. // LATER: Why is hideDialog between begin-/endUpdate faster?
  535. editorUi.hideDialog();
  536. }
  537. catch (e)
  538. {
  539. error = e;
  540. }
  541. finally
  542. {
  543. editorUi.editor.graph.model.endUpdate();
  544. }
  545. }
  546. else if (select.value == 'import')
  547. {
  548. editorUi.editor.graph.model.beginUpdate();
  549. try
  550. {
  551. var doc = mxUtils.parseXml(data);
  552. var model = new mxGraphModel();
  553. var codec = new mxCodec(doc);
  554. codec.decode(doc.documentElement, model);
  555. var children = model.getChildren(model.getChildAt(model.getRoot(), 0));
  556. editorUi.editor.graph.setSelectionCells(editorUi.editor.graph.importCells(children));
  557. // LATER: Why is hideDialog between begin-/endUpdate faster?
  558. editorUi.hideDialog();
  559. }
  560. catch (e)
  561. {
  562. error = e;
  563. }
  564. finally
  565. {
  566. editorUi.editor.graph.model.endUpdate();
  567. }
  568. }
  569. if (error != null)
  570. {
  571. mxUtils.alert(error.message);
  572. }
  573. });
  574. okBtn.className = 'geBtn gePrimaryBtn';
  575. div.appendChild(okBtn);
  576. if (!editorUi.editor.cancelFirst)
  577. {
  578. div.appendChild(cancelBtn);
  579. }
  580. this.container = div;
  581. };
  582. /**
  583. *
  584. */
  585. EditDiagramDialog.showNewWindowOption = true;
  586. /**
  587. * Constructs a new export dialog.
  588. */
  589. var ExportDialog = function(editorUi)
  590. {
  591. var graph = editorUi.editor.graph;
  592. var bounds = graph.getGraphBounds();
  593. var scale = graph.view.scale;
  594. var width = Math.ceil(bounds.width / scale);
  595. var height = Math.ceil(bounds.height / scale);
  596. var row, td;
  597. var table = document.createElement('table');
  598. var tbody = document.createElement('tbody');
  599. table.setAttribute('cellpadding', (mxClient.IS_SF) ? '0' : '2');
  600. row = document.createElement('tr');
  601. td = document.createElement('td');
  602. td.style.fontSize = '10pt';
  603. td.style.width = '100px';
  604. mxUtils.write(td, mxResources.get('filename') + ':');
  605. row.appendChild(td);
  606. var nameInput = document.createElement('input');
  607. nameInput.setAttribute('value', editorUi.editor.getOrCreateFilename());
  608. nameInput.style.width = '180px';
  609. td = document.createElement('td');
  610. td.appendChild(nameInput);
  611. row.appendChild(td);
  612. tbody.appendChild(row);
  613. row = document.createElement('tr');
  614. td = document.createElement('td');
  615. td.style.fontSize = '10pt';
  616. mxUtils.write(td, mxResources.get('format') + ':');
  617. row.appendChild(td);
  618. var imageFormatSelect = document.createElement('select');
  619. imageFormatSelect.style.width = '180px';
  620. var pngOption = document.createElement('option');
  621. pngOption.setAttribute('value', 'png');
  622. mxUtils.write(pngOption, mxResources.get('formatPng'));
  623. imageFormatSelect.appendChild(pngOption);
  624. var gifOption = document.createElement('option');
  625. if (ExportDialog.showGifOption)
  626. {
  627. gifOption.setAttribute('value', 'gif');
  628. mxUtils.write(gifOption, mxResources.get('formatGif'));
  629. imageFormatSelect.appendChild(gifOption);
  630. }
  631. var jpgOption = document.createElement('option');
  632. jpgOption.setAttribute('value', 'jpg');
  633. mxUtils.write(jpgOption, mxResources.get('formatJpg'));
  634. imageFormatSelect.appendChild(jpgOption);
  635. var pdfOption = document.createElement('option');
  636. pdfOption.setAttribute('value', 'pdf');
  637. mxUtils.write(pdfOption, mxResources.get('formatPdf'));
  638. imageFormatSelect.appendChild(pdfOption);
  639. var svgOption = document.createElement('option');
  640. svgOption.setAttribute('value', 'svg');
  641. mxUtils.write(svgOption, mxResources.get('formatSvg'));
  642. imageFormatSelect.appendChild(svgOption);
  643. if (ExportDialog.showXmlOption)
  644. {
  645. var xmlOption = document.createElement('option');
  646. xmlOption.setAttribute('value', 'xml');
  647. mxUtils.write(xmlOption, mxResources.get('formatXml'));
  648. imageFormatSelect.appendChild(xmlOption);
  649. }
  650. td = document.createElement('td');
  651. td.appendChild(imageFormatSelect);
  652. row.appendChild(td);
  653. tbody.appendChild(row);
  654. row = document.createElement('tr');
  655. td = document.createElement('td');
  656. td.style.fontSize = '10pt';
  657. mxUtils.write(td, mxResources.get('zoom') + ' (%):');
  658. row.appendChild(td);
  659. var zoomInput = document.createElement('input');
  660. zoomInput.setAttribute('type', 'number');
  661. zoomInput.setAttribute('value', '100');
  662. zoomInput.style.width = '180px';
  663. td = document.createElement('td');
  664. td.appendChild(zoomInput);
  665. row.appendChild(td);
  666. tbody.appendChild(row);
  667. row = document.createElement('tr');
  668. td = document.createElement('td');
  669. td.style.fontSize = '10pt';
  670. mxUtils.write(td, mxResources.get('width') + ':');
  671. row.appendChild(td);
  672. var widthInput = document.createElement('input');
  673. widthInput.setAttribute('value', width);
  674. widthInput.style.width = '180px';
  675. td = document.createElement('td');
  676. td.appendChild(widthInput);
  677. row.appendChild(td);
  678. tbody.appendChild(row);
  679. row = document.createElement('tr');
  680. td = document.createElement('td');
  681. td.style.fontSize = '10pt';
  682. mxUtils.write(td, mxResources.get('height') + ':');
  683. row.appendChild(td);
  684. var heightInput = document.createElement('input');
  685. heightInput.setAttribute('value', height);
  686. heightInput.style.width = '180px';
  687. td = document.createElement('td');
  688. td.appendChild(heightInput);
  689. row.appendChild(td);
  690. tbody.appendChild(row);
  691. row = document.createElement('tr');
  692. td = document.createElement('td');
  693. td.style.fontSize = '10pt';
  694. mxUtils.write(td, mxResources.get('dpi') + ':');
  695. row.appendChild(td);
  696. var dpiSelect = document.createElement('select');
  697. dpiSelect.style.width = '180px';
  698. var dpi100Option = document.createElement('option');
  699. dpi100Option.setAttribute('value', '100');
  700. mxUtils.write(dpi100Option, '100dpi');
  701. dpiSelect.appendChild(dpi100Option);
  702. var dpi200Option = document.createElement('option');
  703. dpi200Option.setAttribute('value', '200');
  704. mxUtils.write(dpi200Option, '200dpi');
  705. dpiSelect.appendChild(dpi200Option);
  706. var dpi300Option = document.createElement('option');
  707. dpi300Option.setAttribute('value', '300');
  708. mxUtils.write(dpi300Option, '300dpi');
  709. dpiSelect.appendChild(dpi300Option);
  710. var dpi400Option = document.createElement('option');
  711. dpi400Option.setAttribute('value', '400');
  712. mxUtils.write(dpi400Option, '400dpi');
  713. dpiSelect.appendChild(dpi400Option);
  714. var dpiCustOption = document.createElement('option');
  715. dpiCustOption.setAttribute('value', 'custom');
  716. mxUtils.write(dpiCustOption, mxResources.get('custom'));
  717. dpiSelect.appendChild(dpiCustOption);
  718. var customDpi = document.createElement('input');
  719. customDpi.style.width = '180px';
  720. customDpi.style.display = 'none';
  721. customDpi.setAttribute('value', '100');
  722. customDpi.setAttribute('type', 'number');
  723. customDpi.setAttribute('min', '50');
  724. customDpi.setAttribute('step', '50');
  725. var zoomUserChanged = false;
  726. mxEvent.addListener(dpiSelect, 'change', function()
  727. {
  728. if (this.value == 'custom')
  729. {
  730. this.style.display = 'none';
  731. customDpi.style.display = '';
  732. customDpi.focus();
  733. }
  734. else
  735. {
  736. customDpi.value = this.value;
  737. if (!zoomUserChanged)
  738. {
  739. zoomInput.value = this.value;
  740. }
  741. }
  742. });
  743. mxEvent.addListener(customDpi, 'change', function()
  744. {
  745. var dpi = parseInt(customDpi.value);
  746. if (isNaN(dpi) || dpi <= 0)
  747. {
  748. customDpi.style.backgroundColor = 'red';
  749. }
  750. else
  751. {
  752. customDpi.style.backgroundColor = '';
  753. if (!zoomUserChanged)
  754. {
  755. zoomInput.value = dpi;
  756. }
  757. }
  758. });
  759. td = document.createElement('td');
  760. td.appendChild(dpiSelect);
  761. td.appendChild(customDpi);
  762. row.appendChild(td);
  763. tbody.appendChild(row);
  764. row = document.createElement('tr');
  765. td = document.createElement('td');
  766. td.style.fontSize = '10pt';
  767. mxUtils.write(td, mxResources.get('background') + ':');
  768. row.appendChild(td);
  769. var transparentCheckbox = document.createElement('input');
  770. transparentCheckbox.setAttribute('type', 'checkbox');
  771. transparentCheckbox.checked = graph.background == null || graph.background == mxConstants.NONE;
  772. td = document.createElement('td');
  773. td.appendChild(transparentCheckbox);
  774. mxUtils.write(td, mxResources.get('transparent'));
  775. row.appendChild(td);
  776. tbody.appendChild(row);
  777. row = document.createElement('tr');
  778. td = document.createElement('td');
  779. td.style.fontSize = '10pt';
  780. mxUtils.write(td, mxResources.get('borderWidth') + ':');
  781. row.appendChild(td);
  782. var borderInput = document.createElement('input');
  783. borderInput.setAttribute('type', 'number');
  784. borderInput.setAttribute('value', ExportDialog.lastBorderValue);
  785. borderInput.style.width = '180px';
  786. td = document.createElement('td');
  787. td.appendChild(borderInput);
  788. row.appendChild(td);
  789. tbody.appendChild(row);
  790. table.appendChild(tbody);
  791. // Handles changes in the export format
  792. function formatChanged()
  793. {
  794. var name = nameInput.value;
  795. var dot = name.lastIndexOf('.');
  796. if (dot > 0)
  797. {
  798. nameInput.value = name.substring(0, dot + 1) + imageFormatSelect.value;
  799. }
  800. else
  801. {
  802. nameInput.value = name + '.' + imageFormatSelect.value;
  803. }
  804. if (imageFormatSelect.value === 'xml')
  805. {
  806. zoomInput.setAttribute('disabled', 'true');
  807. widthInput.setAttribute('disabled', 'true');
  808. heightInput.setAttribute('disabled', 'true');
  809. borderInput.setAttribute('disabled', 'true');
  810. }
  811. else
  812. {
  813. zoomInput.removeAttribute('disabled');
  814. widthInput.removeAttribute('disabled');
  815. heightInput.removeAttribute('disabled');
  816. borderInput.removeAttribute('disabled');
  817. }
  818. if (imageFormatSelect.value === 'png' || imageFormatSelect.value === 'svg' || imageFormatSelect.value === 'pdf')
  819. {
  820. transparentCheckbox.removeAttribute('disabled');
  821. }
  822. else
  823. {
  824. transparentCheckbox.setAttribute('disabled', 'disabled');
  825. }
  826. if (imageFormatSelect.value === 'png')
  827. {
  828. dpiSelect.removeAttribute('disabled');
  829. customDpi.removeAttribute('disabled');
  830. }
  831. else
  832. {
  833. dpiSelect.setAttribute('disabled', 'disabled');
  834. customDpi.setAttribute('disabled', 'disabled');
  835. }
  836. };
  837. mxEvent.addListener(imageFormatSelect, 'change', formatChanged);
  838. formatChanged();
  839. function checkValues()
  840. {
  841. if (widthInput.value * heightInput.value > MAX_AREA || widthInput.value <= 0)
  842. {
  843. widthInput.style.backgroundColor = 'red';
  844. }
  845. else
  846. {
  847. widthInput.style.backgroundColor = '';
  848. }
  849. if (widthInput.value * heightInput.value > MAX_AREA || heightInput.value <= 0)
  850. {
  851. heightInput.style.backgroundColor = 'red';
  852. }
  853. else
  854. {
  855. heightInput.style.backgroundColor = '';
  856. }
  857. };
  858. mxEvent.addListener(zoomInput, 'change', function()
  859. {
  860. zoomUserChanged = true;
  861. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  862. zoomInput.value = parseFloat((s * 100).toFixed(2));
  863. if (width > 0)
  864. {
  865. widthInput.value = Math.floor(width * s);
  866. heightInput.value = Math.floor(height * s);
  867. }
  868. else
  869. {
  870. zoomInput.value = '100';
  871. widthInput.value = width;
  872. heightInput.value = height;
  873. }
  874. checkValues();
  875. });
  876. mxEvent.addListener(widthInput, 'change', function()
  877. {
  878. var s = parseInt(widthInput.value) / width;
  879. if (s > 0)
  880. {
  881. zoomInput.value = parseFloat((s * 100).toFixed(2));
  882. heightInput.value = Math.floor(height * s);
  883. }
  884. else
  885. {
  886. zoomInput.value = '100';
  887. widthInput.value = width;
  888. heightInput.value = height;
  889. }
  890. checkValues();
  891. });
  892. mxEvent.addListener(heightInput, 'change', function()
  893. {
  894. var s = parseInt(heightInput.value) / height;
  895. if (s > 0)
  896. {
  897. zoomInput.value = parseFloat((s * 100).toFixed(2));
  898. widthInput.value = Math.floor(width * s);
  899. }
  900. else
  901. {
  902. zoomInput.value = '100';
  903. widthInput.value = width;
  904. heightInput.value = height;
  905. }
  906. checkValues();
  907. });
  908. row = document.createElement('tr');
  909. td = document.createElement('td');
  910. td.setAttribute('align', 'right');
  911. td.style.paddingTop = '22px';
  912. td.colSpan = 2;
  913. var saveBtn = mxUtils.button(mxResources.get('export'), mxUtils.bind(this, function()
  914. {
  915. if (parseInt(zoomInput.value) <= 0)
  916. {
  917. mxUtils.alert(mxResources.get('drawingEmpty'));
  918. }
  919. else
  920. {
  921. var name = nameInput.value;
  922. var format = imageFormatSelect.value;
  923. var s = Math.max(0, parseFloat(zoomInput.value) || 100) / 100;
  924. var b = Math.max(0, parseInt(borderInput.value));
  925. var bg = graph.background;
  926. var dpi = Math.max(1, parseInt(customDpi.value));
  927. if ((format == 'svg' || format == 'png' || format == 'pdf') && transparentCheckbox.checked)
  928. {
  929. bg = null;
  930. }
  931. else if (bg == null || bg == mxConstants.NONE)
  932. {
  933. bg = '#ffffff';
  934. }
  935. ExportDialog.lastBorderValue = b;
  936. ExportDialog.exportFile(editorUi, name, format, bg, s, b, dpi);
  937. }
  938. }));
  939. saveBtn.className = 'geBtn gePrimaryBtn';
  940. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  941. {
  942. editorUi.hideDialog();
  943. });
  944. cancelBtn.className = 'geBtn';
  945. if (editorUi.editor.cancelFirst)
  946. {
  947. td.appendChild(cancelBtn);
  948. td.appendChild(saveBtn);
  949. }
  950. else
  951. {
  952. td.appendChild(saveBtn);
  953. td.appendChild(cancelBtn);
  954. }
  955. row.appendChild(td);
  956. tbody.appendChild(row);
  957. table.appendChild(tbody);
  958. this.container = table;
  959. };
  960. /**
  961. * Remembers last value for border.
  962. */
  963. ExportDialog.lastBorderValue = 0;
  964. /**
  965. * Global switches for the export dialog.
  966. */
  967. ExportDialog.showGifOption = true;
  968. /**
  969. * Global switches for the export dialog.
  970. */
  971. ExportDialog.showXmlOption = true;
  972. /**
  973. * Hook for getting the export format. Returns null for the default
  974. * intermediate XML export format or a function that returns the
  975. * parameter and value to be used in the request in the form
  976. * key=value, where value should be URL encoded.
  977. */
  978. ExportDialog.exportFile = function(editorUi, name, format, bg, s, b, dpi)
  979. {
  980. var graph = editorUi.editor.graph;
  981. if (format == 'xml')
  982. {
  983. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(editorUi.editor.getGraphXml()), name, format);
  984. }
  985. else if (format == 'svg')
  986. {
  987. ExportDialog.saveLocalFile(editorUi, mxUtils.getXml(graph.getSvg(bg, s, b)), name, format);
  988. }
  989. else
  990. {
  991. var bounds = graph.getGraphBounds();
  992. // New image export
  993. var xmlDoc = mxUtils.createXmlDocument();
  994. var root = xmlDoc.createElement('output');
  995. xmlDoc.appendChild(root);
  996. // Renders graph. Offset will be multiplied with state's scale when painting state.
  997. var xmlCanvas = new mxXmlCanvas2D(root);
  998. xmlCanvas.translate(Math.floor((b / s - bounds.x) / graph.view.scale),
  999. Math.floor((b / s - bounds.y) / graph.view.scale));
  1000. xmlCanvas.scale(s / graph.view.scale);
  1001. var imgExport = new mxImageExport()
  1002. imgExport.drawState(graph.getView().getState(graph.model.root), xmlCanvas);
  1003. // Puts request data together
  1004. var param = 'xml=' + encodeURIComponent(mxUtils.getXml(root));
  1005. var w = Math.ceil(bounds.width * s / graph.view.scale + 2 * b);
  1006. var h = Math.ceil(bounds.height * s / graph.view.scale + 2 * b);
  1007. // Requests image if request is valid
  1008. if (param.length <= MAX_REQUEST_SIZE && w * h < MAX_AREA)
  1009. {
  1010. editorUi.hideDialog();
  1011. var req = new mxXmlRequest(EXPORT_URL, 'format=' + format +
  1012. '&filename=' + encodeURIComponent(name) +
  1013. '&bg=' + ((bg != null) ? bg : 'none') +
  1014. '&w=' + w + '&h=' + h + '&' + param +
  1015. '&dpi=' + dpi);
  1016. req.simulate(document, '_blank');
  1017. }
  1018. else
  1019. {
  1020. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1021. }
  1022. }
  1023. };
  1024. /**
  1025. * Hook for getting the export format. Returns null for the default
  1026. * intermediate XML export format or a function that returns the
  1027. * parameter and value to be used in the request in the form
  1028. * key=value, where value should be URL encoded.
  1029. */
  1030. ExportDialog.saveLocalFile = function(editorUi, data, filename, format)
  1031. {
  1032. if (data.length < MAX_REQUEST_SIZE)
  1033. {
  1034. editorUi.hideDialog();
  1035. var req = new mxXmlRequest(SAVE_URL, 'xml=' + encodeURIComponent(data) + '&filename=' +
  1036. encodeURIComponent(filename) + '&format=' + format);
  1037. req.simulate(document, '_blank');
  1038. }
  1039. else
  1040. {
  1041. mxUtils.alert(mxResources.get('drawingTooLarge'));
  1042. mxUtils.popup(xml);
  1043. }
  1044. };
  1045. /**
  1046. * Constructs a new metadata dialog.
  1047. */
  1048. var EditDataDialog = function(ui, cell)
  1049. {
  1050. var div = document.createElement('div');
  1051. var graph = ui.editor.graph;
  1052. var value = graph.getModel().getValue(cell);
  1053. // Converts the value to an XML node
  1054. if (!mxUtils.isNode(value))
  1055. {
  1056. var doc = mxUtils.createXmlDocument();
  1057. var obj = doc.createElement('object');
  1058. obj.setAttribute('label', value || '');
  1059. value = obj;
  1060. }
  1061. var meta = {};
  1062. try
  1063. {
  1064. var temp = mxUtils.getValue(ui.editor.graph.getCurrentCellStyle(cell), 'metaData', null);
  1065. if (temp != null)
  1066. {
  1067. meta = JSON.parse(temp);
  1068. }
  1069. }
  1070. catch (e)
  1071. {
  1072. // ignore
  1073. }
  1074. // Creates the dialog contents
  1075. var form = new mxForm('properties');
  1076. form.table.style.width = '100%';
  1077. var attrs = value.attributes;
  1078. var names = [];
  1079. var texts = [];
  1080. var count = 0;
  1081. var id = (EditDataDialog.getDisplayIdForCell != null) ?
  1082. EditDataDialog.getDisplayIdForCell(ui, cell) : null;
  1083. var addRemoveButton = function(text, name)
  1084. {
  1085. var wrapper = document.createElement('div');
  1086. wrapper.style.position = 'relative';
  1087. wrapper.style.paddingRight = '20px';
  1088. wrapper.style.boxSizing = 'border-box';
  1089. wrapper.style.width = '100%';
  1090. var removeAttr = document.createElement('a');
  1091. var img = mxUtils.createImage(Dialog.prototype.closeImage);
  1092. img.style.height = '9px';
  1093. img.style.fontSize = '9px';
  1094. img.style.marginBottom = (mxClient.IS_IE11) ? '-1px' : '5px';
  1095. removeAttr.className = 'geButton';
  1096. removeAttr.setAttribute('title', mxResources.get('delete'));
  1097. removeAttr.style.position = 'absolute';
  1098. removeAttr.style.top = '4px';
  1099. removeAttr.style.right = '0px';
  1100. removeAttr.style.margin = '0px';
  1101. removeAttr.style.width = '9px';
  1102. removeAttr.style.height = '9px';
  1103. removeAttr.style.cursor = 'pointer';
  1104. removeAttr.appendChild(img);
  1105. var removeAttrFn = (function(name)
  1106. {
  1107. return function()
  1108. {
  1109. var count = 0;
  1110. for (var j = 0; j < names.length; j++)
  1111. {
  1112. if (names[j] == name)
  1113. {
  1114. texts[j] = null;
  1115. form.table.deleteRow(count + ((id != null) ? 1 : 0));
  1116. break;
  1117. }
  1118. if (texts[j] != null)
  1119. {
  1120. count++;
  1121. }
  1122. }
  1123. };
  1124. })(name);
  1125. mxEvent.addListener(removeAttr, 'click', removeAttrFn);
  1126. var parent = text.parentNode;
  1127. wrapper.appendChild(text);
  1128. wrapper.appendChild(removeAttr);
  1129. parent.appendChild(wrapper);
  1130. };
  1131. var addTextArea = function(index, name, value)
  1132. {
  1133. names[index] = name;
  1134. texts[index] = form.addTextarea(names[count] + ':', value, 2);
  1135. texts[index].style.width = '100%';
  1136. if (value.indexOf('\n') > 0)
  1137. {
  1138. texts[index].setAttribute('rows', '2');
  1139. }
  1140. addRemoveButton(texts[index], name);
  1141. if (meta[name] != null && meta[name].editable == false)
  1142. {
  1143. texts[index].setAttribute('disabled', 'disabled');
  1144. }
  1145. };
  1146. var temp = [];
  1147. var isLayer = graph.getModel().getParent(cell) == graph.getModel().getRoot();
  1148. for (var i = 0; i < attrs.length; i++)
  1149. {
  1150. if ((isLayer || attrs[i].nodeName != 'label') && attrs[i].nodeName != 'placeholders')
  1151. {
  1152. temp.push({name: attrs[i].nodeName, value: attrs[i].nodeValue});
  1153. }
  1154. }
  1155. // Sorts by name
  1156. temp.sort(function(a, b)
  1157. {
  1158. if (a.name < b.name)
  1159. {
  1160. return -1;
  1161. }
  1162. else if (a.name > b.name)
  1163. {
  1164. return 1;
  1165. }
  1166. else
  1167. {
  1168. return 0;
  1169. }
  1170. });
  1171. if (id != null)
  1172. {
  1173. var text = document.createElement('div');
  1174. text.style.width = '100%';
  1175. text.style.fontSize = '11px';
  1176. text.style.textAlign = 'center';
  1177. mxUtils.write(text, id);
  1178. form.addField(mxResources.get('id') + ':', text);
  1179. }
  1180. for (var i = 0; i < temp.length; i++)
  1181. {
  1182. addTextArea(count, temp[i].name, temp[i].value);
  1183. count++;
  1184. }
  1185. var top = document.createElement('div');
  1186. top.style.cssText = 'position:absolute;left:30px;right:30px;overflow-y:auto;top:30px;bottom:80px;';
  1187. top.appendChild(form.table);
  1188. var newProp = document.createElement('div');
  1189. newProp.style.boxSizing = 'border-box';
  1190. newProp.style.paddingRight = '160px';
  1191. newProp.style.whiteSpace = 'nowrap';
  1192. newProp.style.marginTop = '6px';
  1193. newProp.style.width = '100%';
  1194. var nameInput = document.createElement('input');
  1195. nameInput.setAttribute('placeholder', mxResources.get('enterPropertyName'));
  1196. nameInput.setAttribute('type', 'text');
  1197. nameInput.setAttribute('size', (mxClient.IS_IE || mxClient.IS_IE11) ? '36' : '40');
  1198. nameInput.style.boxSizing = 'border-box';
  1199. nameInput.style.marginLeft = '2px';
  1200. nameInput.style.width = '100%';
  1201. newProp.appendChild(nameInput);
  1202. top.appendChild(newProp);
  1203. div.appendChild(top);
  1204. var addBtn = mxUtils.button(mxResources.get('addProperty'), function()
  1205. {
  1206. var name = nameInput.value;
  1207. // Avoid ':' in attribute names which seems to be valid in Chrome
  1208. if (name.length > 0 && name != 'label' && name != 'placeholders' && name.indexOf(':') < 0)
  1209. {
  1210. try
  1211. {
  1212. var idx = mxUtils.indexOf(names, name);
  1213. if (idx >= 0 && texts[idx] != null)
  1214. {
  1215. texts[idx].focus();
  1216. }
  1217. else
  1218. {
  1219. // Checks if the name is valid
  1220. var clone = value.cloneNode(false);
  1221. clone.setAttribute(name, '');
  1222. if (idx >= 0)
  1223. {
  1224. names.splice(idx, 1);
  1225. texts.splice(idx, 1);
  1226. }
  1227. names.push(name);
  1228. var text = form.addTextarea(name + ':', '', 2);
  1229. text.style.width = '100%';
  1230. texts.push(text);
  1231. addRemoveButton(text, name);
  1232. text.focus();
  1233. }
  1234. addBtn.setAttribute('disabled', 'disabled');
  1235. nameInput.value = '';
  1236. }
  1237. catch (e)
  1238. {
  1239. mxUtils.alert(e);
  1240. }
  1241. }
  1242. else
  1243. {
  1244. mxUtils.alert(mxResources.get('invalidName'));
  1245. }
  1246. });
  1247. this.init = function()
  1248. {
  1249. if (texts.length > 0)
  1250. {
  1251. texts[0].focus();
  1252. }
  1253. else
  1254. {
  1255. nameInput.focus();
  1256. }
  1257. };
  1258. addBtn.setAttribute('title', mxResources.get('addProperty'));
  1259. addBtn.setAttribute('disabled', 'disabled');
  1260. addBtn.style.textOverflow = 'ellipsis';
  1261. addBtn.style.position = 'absolute';
  1262. addBtn.style.overflow = 'hidden';
  1263. addBtn.style.width = '144px';
  1264. addBtn.style.right = '0px';
  1265. addBtn.className = 'geBtn';
  1266. newProp.appendChild(addBtn);
  1267. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1268. {
  1269. ui.hideDialog.apply(ui, arguments);
  1270. });
  1271. cancelBtn.className = 'geBtn';
  1272. var applyBtn = mxUtils.button(mxResources.get('apply'), function()
  1273. {
  1274. try
  1275. {
  1276. ui.hideDialog.apply(ui, arguments);
  1277. // Clones and updates the value
  1278. value = value.cloneNode(true);
  1279. var removeLabel = false;
  1280. for (var i = 0; i < names.length; i++)
  1281. {
  1282. if (texts[i] == null)
  1283. {
  1284. value.removeAttribute(names[i]);
  1285. }
  1286. else
  1287. {
  1288. value.setAttribute(names[i], texts[i].value);
  1289. removeLabel = removeLabel || (names[i] == 'placeholder' &&
  1290. value.getAttribute('placeholders') == '1');
  1291. }
  1292. }
  1293. // Removes label if placeholder is assigned
  1294. if (removeLabel)
  1295. {
  1296. value.removeAttribute('label');
  1297. }
  1298. // Updates the value of the cell (undoable)
  1299. graph.getModel().setValue(cell, value);
  1300. }
  1301. catch (e)
  1302. {
  1303. mxUtils.alert(e);
  1304. }
  1305. });
  1306. applyBtn.className = 'geBtn gePrimaryBtn';
  1307. function updateAddBtn()
  1308. {
  1309. if (nameInput.value.length > 0)
  1310. {
  1311. addBtn.removeAttribute('disabled');
  1312. }
  1313. else
  1314. {
  1315. addBtn.setAttribute('disabled', 'disabled');
  1316. }
  1317. };
  1318. mxEvent.addListener(nameInput, 'keyup', updateAddBtn);
  1319. // Catches all changes that don't fire a keyup (such as paste via mouse)
  1320. mxEvent.addListener(nameInput, 'change', updateAddBtn);
  1321. var buttons = document.createElement('div');
  1322. buttons.style.cssText = 'position:absolute;left:30px;right:30px;text-align:right;bottom:30px;height:40px;'
  1323. if (ui.editor.graph.getModel().isVertex(cell) || ui.editor.graph.getModel().isEdge(cell))
  1324. {
  1325. var replace = document.createElement('span');
  1326. replace.style.marginRight = '10px';
  1327. var input = document.createElement('input');
  1328. input.setAttribute('type', 'checkbox');
  1329. input.style.marginRight = '6px';
  1330. if (value.getAttribute('placeholders') == '1')
  1331. {
  1332. input.setAttribute('checked', 'checked');
  1333. input.defaultChecked = true;
  1334. }
  1335. mxEvent.addListener(input, 'click', function()
  1336. {
  1337. if (value.getAttribute('placeholders') == '1')
  1338. {
  1339. value.removeAttribute('placeholders');
  1340. }
  1341. else
  1342. {
  1343. value.setAttribute('placeholders', '1');
  1344. }
  1345. });
  1346. replace.appendChild(input);
  1347. mxUtils.write(replace, mxResources.get('placeholders'));
  1348. if (EditDataDialog.placeholderHelpLink != null)
  1349. {
  1350. var link = document.createElement('a');
  1351. link.setAttribute('href', EditDataDialog.placeholderHelpLink);
  1352. link.setAttribute('title', mxResources.get('help'));
  1353. link.setAttribute('target', '_blank');
  1354. link.style.marginLeft = '8px';
  1355. link.style.cursor = 'help';
  1356. var icon = document.createElement('img');
  1357. mxUtils.setOpacity(icon, 50);
  1358. icon.style.height = '16px';
  1359. icon.style.width = '16px';
  1360. icon.setAttribute('border', '0');
  1361. icon.setAttribute('valign', 'middle');
  1362. icon.style.marginTop = (mxClient.IS_IE11) ? '0px' : '-4px';
  1363. icon.setAttribute('src', Editor.helpImage);
  1364. link.appendChild(icon);
  1365. replace.appendChild(link);
  1366. }
  1367. buttons.appendChild(replace);
  1368. }
  1369. if (ui.editor.cancelFirst)
  1370. {
  1371. buttons.appendChild(cancelBtn);
  1372. buttons.appendChild(applyBtn);
  1373. }
  1374. else
  1375. {
  1376. buttons.appendChild(applyBtn);
  1377. buttons.appendChild(cancelBtn);
  1378. }
  1379. div.appendChild(buttons);
  1380. this.container = div;
  1381. };
  1382. /**
  1383. * Optional help link.
  1384. */
  1385. EditDataDialog.getDisplayIdForCell = function(ui, cell)
  1386. {
  1387. var id = null;
  1388. if (ui.editor.graph.getModel().getParent(cell) != null)
  1389. {
  1390. id = cell.getId();
  1391. }
  1392. return id;
  1393. };
  1394. /**
  1395. * Optional help link.
  1396. */
  1397. EditDataDialog.placeholderHelpLink = null;
  1398. /**
  1399. * Constructs a new link dialog.
  1400. */
  1401. var LinkDialog = function(editorUi, initialValue, btnLabel, fn)
  1402. {
  1403. var div = document.createElement('div');
  1404. mxUtils.write(div, mxResources.get('editLink') + ':');
  1405. var inner = document.createElement('div');
  1406. inner.className = 'geTitle';
  1407. inner.style.backgroundColor = 'transparent';
  1408. inner.style.borderColor = 'transparent';
  1409. inner.style.whiteSpace = 'nowrap';
  1410. inner.style.textOverflow = 'clip';
  1411. inner.style.cursor = 'default';
  1412. if (!mxClient.IS_VML)
  1413. {
  1414. inner.style.paddingRight = '20px';
  1415. }
  1416. var linkInput = document.createElement('input');
  1417. linkInput.setAttribute('value', initialValue);
  1418. linkInput.setAttribute('placeholder', 'http://www.example.com/');
  1419. linkInput.setAttribute('type', 'text');
  1420. linkInput.style.marginTop = '6px';
  1421. linkInput.style.width = '400px';
  1422. linkInput.style.backgroundImage = 'url(\'' + Dialog.prototype.clearImage + '\')';
  1423. linkInput.style.backgroundRepeat = 'no-repeat';
  1424. linkInput.style.backgroundPosition = '100% 50%';
  1425. linkInput.style.paddingRight = '14px';
  1426. var cross = document.createElement('div');
  1427. cross.setAttribute('title', mxResources.get('reset'));
  1428. cross.style.position = 'relative';
  1429. cross.style.left = '-16px';
  1430. cross.style.width = '12px';
  1431. cross.style.height = '14px';
  1432. cross.style.cursor = 'pointer';
  1433. // Workaround for inline-block not supported in IE
  1434. cross.style.display = (mxClient.IS_VML) ? 'inline' : 'inline-block';
  1435. cross.style.top = ((mxClient.IS_VML) ? 0 : 3) + 'px';
  1436. // Needed to block event transparency in IE
  1437. cross.style.background = 'url(' + IMAGE_PATH + '/transparent.gif)';
  1438. mxEvent.addListener(cross, 'click', function()
  1439. {
  1440. linkInput.value = '';
  1441. linkInput.focus();
  1442. });
  1443. inner.appendChild(linkInput);
  1444. inner.appendChild(cross);
  1445. div.appendChild(inner);
  1446. this.init = function()
  1447. {
  1448. linkInput.focus();
  1449. if (mxClient.IS_GC || mxClient.IS_FF || document.documentMode >= 5 || mxClient.IS_QUIRKS)
  1450. {
  1451. linkInput.select();
  1452. }
  1453. else
  1454. {
  1455. document.execCommand('selectAll', false, null);
  1456. }
  1457. };
  1458. var btns = document.createElement('div');
  1459. btns.style.marginTop = '18px';
  1460. btns.style.textAlign = 'right';
  1461. mxEvent.addListener(linkInput, 'keypress', function(e)
  1462. {
  1463. if (e.keyCode == 13)
  1464. {
  1465. editorUi.hideDialog();
  1466. fn(linkInput.value);
  1467. }
  1468. });
  1469. var cancelBtn = mxUtils.button(mxResources.get('cancel'), function()
  1470. {
  1471. editorUi.hideDialog();
  1472. });
  1473. cancelBtn.className = 'geBtn';
  1474. if (editorUi.editor.cancelFirst)
  1475. {
  1476. btns.appendChild(cancelBtn);
  1477. }
  1478. var mainBtn = mxUtils.button(btnLabel, function()
  1479. {
  1480. editorUi.hideDialog();
  1481. fn(linkInput.value);
  1482. });
  1483. mainBtn.className = 'geBtn gePrimaryBtn';
  1484. btns.appendChild(mainBtn);
  1485. if (!editorUi.editor.cancelFirst)
  1486. {
  1487. btns.appendChild(cancelBtn);
  1488. }
  1489. div.appendChild(btns);
  1490. this.container = div;
  1491. };
  1492. /**
  1493. *
  1494. */
  1495. var OutlineWindow = function(editorUi, x, y, w, h)
  1496. {
  1497. var graph = editorUi.editor.graph;
  1498. var div = document.createElement('div');
  1499. div.style.position = 'absolute';
  1500. div.style.width = '100%';
  1501. div.style.height = '100%';
  1502. div.style.border = '1px solid whiteSmoke';
  1503. div.style.overflow = 'hidden';
  1504. this.window = new mxWindow(mxResources.get('outline'), div, x, y, w, h, true, true);
  1505. this.window.minimumSize = new mxRectangle(0, 0, 80, 80);
  1506. this.window.destroyOnClose = false;
  1507. this.window.setMaximizable(false);
  1508. this.window.setResizable(true);
  1509. this.window.setClosable(true);
  1510. this.window.setVisible(true);
  1511. this.window.setLocation = function(x, y)
  1512. {
  1513. var iw = window.innerWidth || document.body.clientWidth || document.documentElement.clientWidth;
  1514. var ih = window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight;
  1515. x = Math.max(0, Math.min(x, iw - this.table.clientWidth));
  1516. y = Math.max(0, Math.min(y, ih - this.table.clientHeight - 48));
  1517. if (this.getX() != x || this.getY() != y)
  1518. {
  1519. mxWindow.prototype.setLocation.apply(this, arguments);
  1520. }
  1521. };
  1522. var resizeListener = mxUtils.bind(this, function()
  1523. {
  1524. var x = this.window.getX();
  1525. var y = this.window.getY();
  1526. this.window.setLocation(x, y);
  1527. });
  1528. mxEvent.addListener(window, 'resize', resizeListener);
  1529. var outline = editorUi.createOutline(this.window);
  1530. this.destroy = function()
  1531. {
  1532. mxEvent.removeListener(window, 'resize', resizeListener);
  1533. this.window.destroy();
  1534. outline.destroy();
  1535. }
  1536. this.window.addListener(mxEvent.RESIZE, mxUtils.bind(this, function()
  1537. {
  1538. outline.update(false);
  1539. outline.outline.sizeDidChange();
  1540. }));
  1541. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  1542. {
  1543. this.window.fit();
  1544. outline.suspended = false;
  1545. outline.outline.refresh();
  1546. outline.update();
  1547. }));
  1548. this.window.addListener(mxEvent.HIDE, mxUtils.bind(this, function()
  1549. {
  1550. outline.suspended = true;
  1551. }));
  1552. this.window.addListener(mxEvent.NORMALIZE, mxUtils.bind(this, function()
  1553. {
  1554. outline.suspended = false;
  1555. outline.update();
  1556. }));
  1557. this.window.addListener(mxEvent.MINIMIZE, mxUtils.bind(this, function()
  1558. {
  1559. outline.suspended = true;
  1560. }));
  1561. var outlineCreateGraph = outline.createGraph;
  1562. outline.createGraph = function(container)
  1563. {
  1564. var g = outlineCreateGraph.apply(this, arguments);
  1565. g.gridEnabled = false;
  1566. g.pageScale = graph.pageScale;
  1567. g.pageFormat = graph.pageFormat;
  1568. g.background = (graph.background == null || graph.background == mxConstants.NONE) ? graph.defaultPageBackgroundColor : graph.background;
  1569. g.pageVisible = graph.pageVisible;
  1570. var current = mxUtils.getCurrentStyle(graph.container);
  1571. div.style.backgroundColor = current.backgroundColor;
  1572. return g;
  1573. };
  1574. function update()
  1575. {
  1576. outline.outline.pageScale = graph.pageScale;
  1577. outline.outline.pageFormat = graph.pageFormat;
  1578. outline.outline.pageVisible = graph.pageVisible;
  1579. outline.outline.background = (graph.background == null || graph.background == mxConstants.NONE) ? graph.defaultPageBackgroundColor : graph.background;;
  1580. var current = mxUtils.getCurrentStyle(graph.container);
  1581. div.style.backgroundColor = current.backgroundColor;
  1582. if (graph.view.backgroundPageShape != null && outline.outline.view.backgroundPageShape != null)
  1583. {
  1584. outline.outline.view.backgroundPageShape.fill = graph.view.backgroundPageShape.fill;
  1585. }
  1586. outline.outline.refresh();
  1587. };
  1588. outline.init(div);
  1589. editorUi.editor.addListener('resetGraphView', update);
  1590. editorUi.addListener('pageFormatChanged', update);
  1591. editorUi.addListener('backgroundColorChanged', update);
  1592. editorUi.addListener('backgroundImageChanged', update);
  1593. editorUi.addListener('pageViewChanged', function()
  1594. {
  1595. update();
  1596. outline.update(true);
  1597. });
  1598. if (outline.outline.dialect == mxConstants.DIALECT_SVG)
  1599. {
  1600. var zoomInAction = editorUi.actions.get('zoomIn');
  1601. var zoomOutAction = editorUi.actions.get('zoomOut');
  1602. mxEvent.addMouseWheelListener(function(evt, up)
  1603. {
  1604. var outlineWheel = false;
  1605. var source = mxEvent.getSource(evt);
  1606. while (source != null)
  1607. {
  1608. if (source == outline.outline.view.canvas.ownerSVGElement)
  1609. {
  1610. outlineWheel = true;
  1611. break;
  1612. }
  1613. source = source.parentNode;
  1614. }
  1615. if (outlineWheel)
  1616. {
  1617. if (up)
  1618. {
  1619. zoomInAction.funct();
  1620. }
  1621. else
  1622. {
  1623. zoomOutAction.funct();
  1624. }
  1625. }
  1626. });
  1627. }
  1628. };
  1629. /**
  1630. *
  1631. */
  1632. var LayersWindow = function(editorUi, x, y, w, h)
  1633. {
  1634. var graph = editorUi.editor.graph;
  1635. var div = document.createElement('div');
  1636. div.style.userSelect = 'none';
  1637. div.style.background = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  1638. div.style.border = '1px solid whiteSmoke';
  1639. div.style.height = '100%';
  1640. div.style.marginBottom = '10px';
  1641. div.style.overflow = 'auto';
  1642. var tbarHeight = (!EditorUi.compactUi) ? '30px' : '26px';
  1643. var listDiv = document.createElement('div')
  1644. listDiv.style.backgroundColor = (Dialog.backdropColor == 'white') ? '#dcdcdc' : Dialog.backdropColor;
  1645. listDiv.style.position = 'absolute';
  1646. listDiv.style.overflow = 'auto';
  1647. listDiv.style.left = '0px';
  1648. listDiv.style.right = '0px';
  1649. listDiv.style.top = '0px';
  1650. listDiv.style.bottom = (parseInt(tbarHeight) + 7) + 'px';
  1651. div.appendChild(listDiv);
  1652. var dragSource = null;
  1653. var dropIndex = null;
  1654. mxEvent.addListener(div, 'dragover', function(evt)
  1655. {
  1656. evt.dataTransfer.dropEffect = 'move';
  1657. dropIndex = 0;
  1658. evt.stopPropagation();
  1659. evt.preventDefault();
  1660. });
  1661. // Workaround for "no element found" error in FF
  1662. mxEvent.addListener(div, 'drop', function(evt)
  1663. {
  1664. evt.stopPropagation();
  1665. evt.preventDefault();
  1666. });
  1667. var layerCount = null;
  1668. var selectionLayer = null;
  1669. var ldiv = document.createElement('div');
  1670. ldiv.className = 'geToolbarContainer';
  1671. ldiv.style.position = 'absolute';
  1672. ldiv.style.bottom = '0px';
  1673. ldiv.style.left = '0px';
  1674. ldiv.style.right = '0px';
  1675. ldiv.style.height = tbarHeight;
  1676. ldiv.style.overflow = 'hidden';
  1677. ldiv.style.padding = (!EditorUi.compactUi) ? '1px' : '4px 0px 3px 0px';
  1678. ldiv.style.backgroundColor = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  1679. ldiv.style.borderWidth = '1px 0px 0px 0px';
  1680. ldiv.style.borderColor = '#c3c3c3';
  1681. ldiv.style.borderStyle = 'solid';
  1682. ldiv.style.display = 'block';
  1683. ldiv.style.whiteSpace = 'nowrap';
  1684. if (mxClient.IS_QUIRKS)
  1685. {
  1686. ldiv.style.filter = 'none';
  1687. }
  1688. var link = document.createElement('a');
  1689. link.className = 'geButton';
  1690. if (mxClient.IS_QUIRKS)
  1691. {
  1692. link.style.filter = 'none';
  1693. }
  1694. var removeLink = link.cloneNode();
  1695. removeLink.innerHTML = '<div class="geSprite geSprite-delete" style="display:inline-block;"></div>';
  1696. mxEvent.addListener(removeLink, 'click', function(evt)
  1697. {
  1698. if (graph.isEnabled())
  1699. {
  1700. graph.model.beginUpdate();
  1701. try
  1702. {
  1703. var index = graph.model.root.getIndex(selectionLayer);
  1704. graph.removeCells([selectionLayer], false);
  1705. // Creates default layer if no layer exists
  1706. if (graph.model.getChildCount(graph.model.root) == 0)
  1707. {
  1708. graph.model.add(graph.model.root, new mxCell());
  1709. graph.setDefaultParent(null);
  1710. }
  1711. else if (index > 0 && index <= graph.model.getChildCount(graph.model.root))
  1712. {
  1713. graph.setDefaultParent(graph.model.getChildAt(graph.model.root, index - 1));
  1714. }
  1715. else
  1716. {
  1717. graph.setDefaultParent(null);
  1718. }
  1719. }
  1720. finally
  1721. {
  1722. graph.model.endUpdate();
  1723. }
  1724. }
  1725. mxEvent.consume(evt);
  1726. });
  1727. if (!graph.isEnabled())
  1728. {
  1729. removeLink.className = 'geButton mxDisabled';
  1730. }
  1731. ldiv.appendChild(removeLink);
  1732. var insertLink = link.cloneNode();
  1733. insertLink.setAttribute('title', mxUtils.trim(mxResources.get('moveSelectionTo', ['...'])));
  1734. insertLink.innerHTML = '<div class="geSprite geSprite-insert" style="display:inline-block;"></div>';
  1735. mxEvent.addListener(insertLink, 'click', function(evt)
  1736. {
  1737. if (graph.isEnabled() && !graph.isSelectionEmpty())
  1738. {
  1739. var offset = mxUtils.getOffset(insertLink);
  1740. editorUi.showPopupMenu(mxUtils.bind(this, function(menu, parent)
  1741. {
  1742. for (var i = layerCount - 1; i >= 0; i--)
  1743. {
  1744. (mxUtils.bind(this, function(child)
  1745. {
  1746. var item = menu.addItem(graph.convertValueToString(child) ||
  1747. mxResources.get('background'), null, mxUtils.bind(this, function()
  1748. {
  1749. graph.moveCells(graph.getSelectionCells(), 0, 0, false, child);
  1750. }), parent);
  1751. if (graph.getSelectionCount() == 1 && graph.model.isAncestor(child, graph.getSelectionCell()))
  1752. {
  1753. menu.addCheckmark(item, Editor.checkmarkImage);
  1754. }
  1755. }))(graph.model.getChildAt(graph.model.root, i));
  1756. }
  1757. }), offset.x, offset.y + insertLink.offsetHeight, evt);
  1758. }
  1759. });
  1760. ldiv.appendChild(insertLink);
  1761. var dataLink = link.cloneNode();
  1762. dataLink.innerHTML = '<div class="geSprite geSprite-dots" style="display:inline-block;"></div>';
  1763. dataLink.setAttribute('title', mxResources.get('rename'));
  1764. mxEvent.addListener(dataLink, 'click', function(evt)
  1765. {
  1766. if (graph.isEnabled())
  1767. {
  1768. editorUi.showDataDialog(selectionLayer);
  1769. }
  1770. mxEvent.consume(evt);
  1771. });
  1772. if (!graph.isEnabled())
  1773. {
  1774. dataLink.className = 'geButton mxDisabled';
  1775. }
  1776. ldiv.appendChild(dataLink);
  1777. function renameLayer(layer)
  1778. {
  1779. if (graph.isEnabled() && layer != null)
  1780. {
  1781. var label = graph.convertValueToString(layer);
  1782. var dlg = new FilenameDialog(editorUi, label || mxResources.get('background'), mxResources.get('rename'), mxUtils.bind(this, function(newValue)
  1783. {
  1784. if (newValue != null)
  1785. {
  1786. graph.cellLabelChanged(layer, newValue);
  1787. }
  1788. }), mxResources.get('enterName'));
  1789. editorUi.showDialog(dlg.container, 300, 100, true, true);
  1790. dlg.init();
  1791. }
  1792. };
  1793. var duplicateLink = link.cloneNode();
  1794. duplicateLink.innerHTML = '<div class="geSprite geSprite-duplicate" style="display:inline-block;"></div>';
  1795. mxEvent.addListener(duplicateLink, 'click', function(evt)
  1796. {
  1797. if (graph.isEnabled())
  1798. {
  1799. var newCell = null;
  1800. graph.model.beginUpdate();
  1801. try
  1802. {
  1803. newCell = graph.cloneCell(selectionLayer);
  1804. graph.cellLabelChanged(newCell, mxResources.get('untitledLayer'));
  1805. newCell.setVisible(true);
  1806. newCell = graph.addCell(newCell, graph.model.root);
  1807. graph.setDefaultParent(newCell);
  1808. }
  1809. finally
  1810. {
  1811. graph.model.endUpdate();
  1812. }
  1813. if (newCell != null && !graph.isCellLocked(newCell))
  1814. {
  1815. graph.selectAll(newCell);
  1816. }
  1817. }
  1818. });
  1819. if (!graph.isEnabled())
  1820. {
  1821. duplicateLink.className = 'geButton mxDisabled';
  1822. }
  1823. ldiv.appendChild(duplicateLink);
  1824. var addLink = link.cloneNode();
  1825. addLink.innerHTML = '<div class="geSprite geSprite-plus" style="display:inline-block;"></div>';
  1826. addLink.setAttribute('title', mxResources.get('addLayer'));
  1827. mxEvent.addListener(addLink, 'click', function(evt)
  1828. {
  1829. if (graph.isEnabled())
  1830. {
  1831. graph.model.beginUpdate();
  1832. try
  1833. {
  1834. var cell = graph.addCell(new mxCell(mxResources.get('untitledLayer')), graph.model.root);
  1835. graph.setDefaultParent(cell);
  1836. }
  1837. finally
  1838. {
  1839. graph.model.endUpdate();
  1840. }
  1841. }
  1842. mxEvent.consume(evt);
  1843. });
  1844. if (!graph.isEnabled())
  1845. {
  1846. addLink.className = 'geButton mxDisabled';
  1847. }
  1848. ldiv.appendChild(addLink);
  1849. div.appendChild(ldiv);
  1850. function refresh()
  1851. {
  1852. layerCount = graph.model.getChildCount(graph.model.root)
  1853. listDiv.innerHTML = '';
  1854. function addLayer(index, label, child, defaultParent)
  1855. {
  1856. var ldiv = document.createElement('div');
  1857. ldiv.className = 'geToolbarContainer';
  1858. ldiv.style.overflow = 'hidden';
  1859. ldiv.style.position = 'relative';
  1860. ldiv.style.padding = '4px';
  1861. ldiv.style.height = '22px';
  1862. ldiv.style.display = 'block';
  1863. ldiv.style.backgroundColor = (Dialog.backdropColor == 'white') ? 'whiteSmoke' : Dialog.backdropColor;
  1864. ldiv.style.borderWidth = '0px 0px 1px 0px';
  1865. ldiv.style.borderColor = '#c3c3c3';
  1866. ldiv.style.borderStyle = 'solid';
  1867. ldiv.style.whiteSpace = 'nowrap';
  1868. ldiv.setAttribute('title', label);
  1869. var left = document.createElement('div');
  1870. left.style.display = 'inline-block';
  1871. left.style.width = '100%';
  1872. left.style.textOverflow = 'ellipsis';
  1873. left.style.overflow = 'hidden';
  1874. mxEvent.addListener(ldiv, 'dragover', function(evt)
  1875. {
  1876. evt.dataTransfer.dropEffect = 'move';
  1877. dropIndex = index;
  1878. evt.stopPropagation();
  1879. evt.preventDefault();
  1880. });
  1881. mxEvent.addListener(ldiv, 'dragstart', function(evt)
  1882. {
  1883. dragSource = ldiv;
  1884. // Workaround for no DnD on DIV in FF
  1885. if (mxClient.IS_FF)
  1886. {
  1887. // LATER: Check what triggers a parse as XML on this in FF after drop
  1888. evt.dataTransfer.setData('Text', '<layer/>');
  1889. }
  1890. });
  1891. mxEvent.addListener(ldiv, 'dragend', function(evt)
  1892. {
  1893. if (dragSource != null && dropIndex != null)
  1894. {
  1895. graph.addCell(child, graph.model.root, dropIndex);
  1896. }
  1897. dragSource = null;
  1898. dropIndex = null;
  1899. evt.stopPropagation();
  1900. evt.preventDefault();
  1901. });
  1902. var btn = document.createElement('img');
  1903. btn.setAttribute('draggable', 'false');
  1904. btn.setAttribute('align', 'top');
  1905. btn.setAttribute('border', '0');
  1906. btn.style.padding = '4px';
  1907. btn.setAttribute('title', mxResources.get('lockUnlock'));
  1908. var style = graph.getCurrentCellStyle(child);
  1909. if (mxUtils.getValue(style, 'locked', '0') == '1')
  1910. {
  1911. btn.setAttribute('src', Dialog.prototype.lockedImage);
  1912. }
  1913. else
  1914. {
  1915. btn.setAttribute('src', Dialog.prototype.unlockedImage);
  1916. }
  1917. if (graph.isEnabled())
  1918. {
  1919. btn.style.cursor = 'pointer';
  1920. }
  1921. mxEvent.addListener(btn, 'click', function(evt)
  1922. {
  1923. if (graph.isEnabled())
  1924. {
  1925. var value = null;
  1926. graph.getModel().beginUpdate();
  1927. try
  1928. {
  1929. value = (mxUtils.getValue(style, 'locked', '0') == '1') ? null : '1';
  1930. graph.setCellStyles('locked', value, [child]);
  1931. }
  1932. finally
  1933. {
  1934. graph.getModel().endUpdate();
  1935. }
  1936. if (value == '1')
  1937. {
  1938. graph.removeSelectionCells(graph.getModel().getDescendants(child));
  1939. }
  1940. mxEvent.consume(evt);
  1941. }
  1942. });
  1943. left.appendChild(btn);
  1944. var inp = document.createElement('input');
  1945. inp.setAttribute('type', 'checkbox');
  1946. inp.setAttribute('title', mxResources.get('hideIt', [child.value || mxResources.get('background')]));
  1947. inp.style.marginLeft = '4px';
  1948. inp.style.marginRight = '6px';
  1949. inp.style.marginTop = '4px';
  1950. left.appendChild(inp);
  1951. if (graph.model.isVisible(child))
  1952. {
  1953. inp.setAttribute('checked', 'checked');
  1954. inp.defaultChecked = true;
  1955. }
  1956. mxEvent.addListener(inp, 'click', function(evt)
  1957. {
  1958. graph.model.setVisible(child, !graph.model.isVisible(child));
  1959. mxEvent.consume(evt);
  1960. });
  1961. mxUtils.write(left, label);
  1962. ldiv.appendChild(left);
  1963. if (graph.isEnabled())
  1964. {
  1965. // Fallback if no drag and drop is available
  1966. if (mxClient.IS_TOUCH || mxClient.IS_POINTER || mxClient.IS_VML ||
  1967. (mxClient.IS_IE && document.documentMode < 10))
  1968. {
  1969. var right = document.createElement('div');
  1970. right.style.display = 'block';
  1971. right.style.textAlign = 'right';
  1972. right.style.whiteSpace = 'nowrap';
  1973. right.style.position = 'absolute';
  1974. right.style.right = '6px';
  1975. right.style.top = '6px';
  1976. // Poor man's change layer order
  1977. if (index > 0)
  1978. {
  1979. var img2 = document.createElement('a');
  1980. img2.setAttribute('title', mxResources.get('toBack'));
  1981. img2.className = 'geButton';
  1982. img2.style.cssFloat = 'none';
  1983. img2.innerHTML = '&#9660;';
  1984. img2.style.width = '14px';
  1985. img2.style.height = '14px';
  1986. img2.style.fontSize = '14px';
  1987. img2.style.margin = '0px';
  1988. img2.style.marginTop = '-1px';
  1989. right.appendChild(img2);
  1990. mxEvent.addListener(img2, 'click', function(evt)
  1991. {
  1992. if (graph.isEnabled())
  1993. {
  1994. graph.addCell(child, graph.model.root, index - 1);
  1995. }
  1996. mxEvent.consume(evt);
  1997. });
  1998. }
  1999. if (index >= 0 && index < layerCount - 1)
  2000. {
  2001. var img1 = document.createElement('a');
  2002. img1.setAttribute('title', mxResources.get('toFront'));
  2003. img1.className = 'geButton';
  2004. img1.style.cssFloat = 'none';
  2005. img1.innerHTML = '&#9650;';
  2006. img1.style.width = '14px';
  2007. img1.style.height = '14px';
  2008. img1.style.fontSize = '14px';
  2009. img1.style.margin = '0px';
  2010. img1.style.marginTop = '-1px';
  2011. right.appendChild(img1);
  2012. mxEvent.addListener(img1, 'click', function(evt)
  2013. {
  2014. if (graph.isEnabled())
  2015. {
  2016. graph.addCell(child, graph.model.root, index + 1);
  2017. }
  2018. mxEvent.consume(evt);
  2019. });
  2020. }
  2021. ldiv.appendChild(right);
  2022. }
  2023. if (mxClient.IS_SVG && (!mxClient.IS_IE || document.documentMode >= 10))
  2024. {
  2025. ldiv.setAttribute('draggable', 'true');
  2026. ldiv.style.cursor = 'move';
  2027. }
  2028. }
  2029. mxEvent.addListener(ldiv, 'dblclick', function(evt)
  2030. {
  2031. var nodeName = mxEvent.getSource(evt).nodeName;
  2032. if (nodeName != 'INPUT' && nodeName != 'IMG')
  2033. {
  2034. renameLayer(child);
  2035. mxEvent.consume(evt);
  2036. }
  2037. });
  2038. if (graph.getDefaultParent() == child)
  2039. {
  2040. ldiv.style.background = (Dialog.backdropColor == 'white') ? '#e6eff8' : '#505759';
  2041. ldiv.style.fontWeight = (graph.isEnabled()) ? 'bold' : '';
  2042. selectionLayer = child;
  2043. }
  2044. else
  2045. {
  2046. mxEvent.addListener(ldiv, 'click', function(evt)
  2047. {
  2048. if (graph.isEnabled())
  2049. {
  2050. graph.setDefaultParent(defaultParent);
  2051. graph.view.setCurrentRoot(null);
  2052. }
  2053. });
  2054. }
  2055. listDiv.appendChild(ldiv);
  2056. };
  2057. // Cannot be moved or deleted
  2058. for (var i = layerCount - 1; i >= 0; i--)
  2059. {
  2060. (mxUtils.bind(this, function(child)
  2061. {
  2062. addLayer(i, graph.convertValueToString(child) ||
  2063. mxResources.get('background'), child, child);
  2064. }))(graph.model.getChildAt(graph.model.root, i));
  2065. }
  2066. var label = graph.convertValueToString(selectionLayer) || mxResources.get('background');
  2067. removeLink.setAttribute('title', mxResources.get('removeIt', [label]));
  2068. duplicateLink.setAttribute('title', mxResources.get('duplicateIt', [label]));
  2069. dataLink.setAttribute('title', mxResources.get('editData'));
  2070. if (graph.isSelectionEmpty())
  2071. {
  2072. insertLink.className = 'geButton mxDisabled';
  2073. }
  2074. };
  2075. refresh();
  2076. graph.model.addListener(mxEvent.CHANGE, refresh);
  2077. graph.addListener('defaultParentChanged', refresh);
  2078. graph.selectionModel.addListener(mxEvent.CHANGE, function()
  2079. {
  2080. if (graph.isSelectionEmpty())
  2081. {
  2082. insertLink.className = 'geButton mxDisabled';
  2083. }
  2084. else
  2085. {
  2086. insertLink.className = 'geButton';
  2087. }
  2088. });
  2089. this.window = new mxWindow(mxResources.get('layers'), div, x, y, w, h, true, true);
  2090. this.window.minimumSize = new mxRectangle(0, 0, 120, 120);
  2091. this.window.destroyOnClose = false;
  2092. this.window.setMaximizable(false);
  2093. this.window.setResizable(true);
  2094. this.window.setClosable(true);
  2095. this.window.setVisible(true);
  2096. this.init = function()
  2097. {
  2098. listDiv.scrollTop = listDiv.scrollHeight - listDiv.clientHeight;
  2099. };
  2100. this.window.addListener(mxEvent.SHOW, mxUtils.bind(this, function()
  2101. {
  2102. this.window.fit();
  2103. }));
  2104. // Make refresh available via instance
  2105. this.refreshLayers = refresh;
  2106. this.window.setLocation = function(x, y)
  2107. {
  2108. var iw = window.innerWidth || document.body.clientWidth || document.documentElement.clientWidth;
  2109. var ih = window.innerHeight || document.body.clientHeight || document.documentElement.clientHeight;
  2110. x = Math.max(0, Math.min(x, iw - this.table.clientWidth));
  2111. y = Math.max(0, Math.min(y, ih - this.table.clientHeight - 48));
  2112. if (this.getX() != x || this.getY() != y)
  2113. {
  2114. mxWindow.prototype.setLocation.apply(this, arguments);
  2115. }
  2116. };
  2117. var resizeListener = mxUtils.bind(this, function()
  2118. {
  2119. var x = this.window.getX();
  2120. var y = this.window.getY();
  2121. this.window.setLocation(x, y);
  2122. });
  2123. mxEvent.addListener(window, 'resize', resizeListener);
  2124. this.destroy = function()
  2125. {
  2126. mxEvent.removeListener(window, 'resize', resizeListener);
  2127. this.window.destroy();
  2128. }
  2129. };