window_management.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. /* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling
  2. * Copyright 2011 by the AToMPM team and licensed under the LGPL
  3. * See COPYING.lesser and README.md in the root of this project for full details
  4. */
  5. ///////////////////////////////////////////////////////////////////////////////
  6. // DEPRECATED FUNCTIONS
  7. ///////////////////////////////////////////////////////////////////////////////
  8. function _openDialog(type, args, callback){
  9. AtomPMClient.alertDeprecatedFunctionCall("_openDialog");
  10. WindowManagement.openDialog(type, args, callback);
  11. }
  12. function _spawnClient(fname,callbackURL){
  13. AtomPMClient.alertDeprecatedFunctionCall("_spawnClient");
  14. WindowManagement.spawnClient(fname, callbackURL);
  15. }
  16. function _spawnHeadlessClient(context,onready,onchlog){
  17. AtomPMClient.alertDeprecatedFunctionCall("_spawnHeadlessClient");
  18. WindowManagement.spawnHeadlessClient(context, onready, onchlog);
  19. }
  20. function __showDialog(){
  21. alert(AtomPMClient);
  22. AtomPMClient.alertDeprecatedFunctionCall("__showDialog");
  23. WindowManagement.showDialog();
  24. }
  25. function __closeDialog(){
  26. AtomPMClient.alertDeprecatedFunctionCall("__closeDialog");
  27. WindowManagement.closeDialog();
  28. }
  29. ///////////////////////////////////////////////////////////////////////////////
  30. //DEPRECATED FUNCTIONS
  31. ///////////////////////////////////////////////////////////////////////////////
  32. var __dialog_stack = [];
  33. WindowManagement = function(){
  34. /**
  35. * Hides the login screen
  36. */
  37. this.hideLoginScreen = function()
  38. {
  39. //$('#div_login').style.display = 'none';
  40. $('#div_login').css('display', 'none');
  41. __setCanvasScrolling(true);
  42. };
  43. /**
  44. * Shows the login screen
  45. */
  46. this.showLoginScreen = function()
  47. {
  48. //$('#div_login').style.display = 'inline';
  49. $('#div_login').css('display', 'inline');
  50. __setCanvasScrolling(false);
  51. };
  52. //Todo: Shred this function into smaller functions, as this should
  53. // really just amount to a switch statement
  54. //TBI: complete comments about each dialog (copy from user's manual)
  55. /**
  56. * Opens a general dialog window
  57. */
  58. this.openDialog = function(type,args,callback)
  59. {
  60. args = args || {};
  61. function error(err,fatal)
  62. {
  63. console.error("Error! " + err);
  64. GUIUtils.setupAndShowDialog(
  65. [GUIUtils.getTextSpan(
  66. err,
  67. 'error')],
  68. undefined,
  69. (fatal ? __NO_BUTTONS : __ONE_BUTTON),
  70. (fatal ? 'FATAL ERROR (restart required)' : 'ERROR'));
  71. //console.error(err,args);
  72. }
  73. // TODO: Fix this, convert to JQuery
  74. if( type == _CLOUD_DATA_MANAGER )
  75. /* args: extensions,readonly,title */
  76. {
  77. HttpUtils.httpReq(
  78. 'GET',
  79. HttpUtils.url('/filelist',__NO_WID),
  80. undefined,
  81. function(statusCode,resp){
  82. var fnames = __localizeFilenames(
  83. __filterFilenamesByExtension(
  84. resp.split('\n'),
  85. args['extensions'] || ['.*'])).sort(),
  86. maxFnameLength =
  87. utils.max(fnames, function(_) {
  88. return _.length;
  89. }),
  90. fileb = FileBrowser.getFileBrowser(fnames,true),
  91. feedbackarea = $('<div>'),
  92. feedback = GUIUtils.getTextSpan(''),
  93. progressbar = $('<div>'),
  94. progressfill = $('<div>'),
  95. download = $('<div>'),
  96. trash = $('<div>'),
  97. div_dldel = $('<div>'),
  98. hldropzone =
  99. /* highlight or unhighlight the dropzone */
  100. function(zone)
  101. {
  102. if( zone == undefined )
  103. {
  104. fileb['filepane']().attr('class', 'fileb_pane');
  105. download.attr('class', 'dropzone');
  106. trash.attr('class', 'dropzone');
  107. }
  108. else if( zone == 'upload' )
  109. {
  110. var filepane = fileb['filepane']();
  111. filepane.attr('class', 'fileb_pane droppable');
  112. filepane.get(0).ondrop = onfilepanedrop;
  113. }
  114. else if( zone == 'dl/del' )
  115. {
  116. download.attr('class', 'dropzone droppable');
  117. trash.attr('class', 'dropzone droppable');
  118. }
  119. },
  120. cancelevt =
  121. /* prevent event bubbling */
  122. function(event)
  123. {
  124. event.stopPropagation();
  125. event.preventDefault();
  126. return false;
  127. },
  128. ondownloaddrop =
  129. function(event)
  130. {
  131. cancelevt(event);
  132. hldropzone();
  133. window.location.assign(event.dataTransfer.getData('uri'));
  134. },
  135. ontrashdrop =
  136. function(event)
  137. {
  138. cancelevt(event);
  139. hldropzone();
  140. var uri = event.dataTransfer.getData('uri');
  141. DataUtils.deleteFromCloud(uri,
  142. function(statusCode,resp)
  143. {
  144. if( ! utils.isHttpSuccessCode(statusCode) )
  145. return error(resp);
  146. feedback.html('deleted '+uri.match(/.*\/(.+)\.file/)[1]);
  147. });
  148. },
  149. onfilepanedrop =
  150. /* react to file drop from desktop
  151. 1. exit with error if non-zip files
  152. 2. move to handleFiles() otherwise */
  153. function(event)
  154. {
  155. cancelevt(event);
  156. hldropzone();
  157. var files = event.dataTransfer.files;
  158. for( var i=0; i<files.length; i++ )
  159. if( files[i].type != 'application/zip' )
  160. return error('uploaded files must zip archives');
  161. handleFiles(event.dataTransfer.files,0);
  162. },
  163. handleFiles =
  164. /* handle each dropped file from desktop
  165. 1. retrieve next file to handle
  166. 2. update feedback message and show progress bar
  167. 3. init file reader event handlers
  168. . onprogress updates progress bar
  169. . onload reacts to upload completion by adjusting
  170. feedback message, hiding progress bar and sending
  171. file to backend
  172. 4. start upload */
  173. function(files,i)
  174. {
  175. if( i >= files.length)
  176. return;
  177. var file = files[i];
  178. feedback.html('uploading '+file.name);
  179. progressbar.css("display", 'inline-block');
  180. var reader = new FileReader();
  181. reader.onprogress =
  182. function(event)
  183. {
  184. if( event.lengthComputable )
  185. progressfill.css("width",
  186. (100*event.loaded/event.total)+'%');
  187. };
  188. reader.onload =
  189. function(event)
  190. {
  191. progressfill.css("width", '100%');
  192. feedback.html('processing '+file.name+' ...');
  193. progressbar.css("display", 'none');
  194. DataUtils.uploadToCloud(
  195. fileb['getcurrfolder'](),
  196. event.target.result,
  197. function(statusCode,resp)
  198. {
  199. if( ! utils.isHttpSuccessCode(statusCode) )
  200. return error(resp);
  201. feedback.html('successfully processed '+file.name);
  202. handleFiles(files,++i);
  203. });
  204. };
  205. reader.readAsBinaryString(file);
  206. },
  207. cloudmgrClosed =
  208. function()
  209. {
  210. return fileb['filebrowser'].parent() == null;
  211. };
  212. document.body.ondragenter =
  213. /* show dropzone when file drag from desktop enters window */
  214. function(event)
  215. {
  216. if(cloudmgrClosed()) return true;
  217. cancelevt(event);
  218. hldropzone(
  219. (event.dataTransfer.effectAllowed == 'copyMove' ? 'dl/del' : 'upload'));
  220. return false;
  221. };
  222. document.body.ondragleave =
  223. /* hide dropzone when file drag from desktop leaves window (which
  224. causes event.pageX == 0) */
  225. function(event)
  226. {
  227. if(cloudmgrClosed()) return true;
  228. cancelevt(event);
  229. if( event.pageX == 0 )
  230. hldropzone();
  231. return false;
  232. };
  233. document.body.ondrop =
  234. function(event)
  235. {
  236. if(cloudmgrClosed()) return true;
  237. cancelevt(event);
  238. hldropzone();
  239. console.warn('non-dropzone drops are ignored');
  240. return false;
  241. };
  242. fileb['filebrowser'].attr('title',
  243. 'drag\'n\'drop files to file pane to upload\n'+
  244. '(close and re-open dialog to observe effects)');
  245. download.attr('title', 'drag\'n\'drop files from file pane to download');
  246. trash.attr('title', 'drag\'n\'drop files from file pane to delete\n'+
  247. '(close and re-open dialog to observe effects)');
  248. progressfill.attr('class', 'progress_fill');
  249. progressfill.html('&nbsp;');
  250. progressbar.attr('class', 'progress_bar');
  251. progressbar.append(progressfill);
  252. progressbar.css("display", 'none');
  253. feedbackarea.append(feedback);
  254. feedbackarea.append(progressbar);
  255. download.css("backgroundImage", 'url(client/media/download.png)');
  256. trash.css("backgroundImage", 'url(client/media/trash.png)');
  257. download.attr('class', 'dropzone');
  258. trash.attr('class', 'dropzone');
  259. download.css("cssFloat", 'left');
  260. trash.css("cssFloat", 'right');
  261. download.get(0).ondragover = cancelevt;
  262. trash.get(0).ondragover = cancelevt;
  263. download.get(0).ondrop = ondownloaddrop;
  264. trash.get(0).ondrop = ontrashdrop;
  265. div_dldel.append(download);
  266. div_dldel.append(trash);
  267. if( args['readonly'] )
  268. trash.css("display", 'none');
  269. GUIUtils.setupAndShowDialog(
  270. [fileb['filebrowser'],div_dldel,feedbackarea],
  271. undefined,
  272. __ONE_BUTTON,
  273. args['title'] ||
  274. 'manage your cloud data\n(note:: you must close and re-open '+
  275. 'dialog to view upload and deletion effects)');
  276. });
  277. }
  278. else if( type == _CUSTOM )
  279. /* args: widgets, title
  280. 'widgets' must be a list where each entry is either
  281. ['id':___,'type':'input','label':___,'default':___], or
  282. ['id':___,'type':'select','choices':___,'multipleChoice':___] */
  283. {
  284. var elements = [],
  285. getinputs = [];
  286. args['widgets'].forEach(
  287. function(w)
  288. {
  289. if( w['type'] == 'select' )
  290. {
  291. var select = GUIUtils.getSelector(w['choices'],w['multipleChoice']);
  292. getinputs.push(function(_)
  293. {
  294. _[w['id']] = HttpUtils.getSelectorSelection(select);
  295. });
  296. elements.push(select);
  297. }
  298. else if( w['type'] == 'input' )
  299. {
  300. var label = GUIUtils.getTextSpan(w['label'] || ''),
  301. input = GUIUtils.getStringInput(w['default'] || '');
  302. getinputs.push(function(_)
  303. {
  304. _[w['id']] = input[0].value;
  305. });
  306. elements.push(label,input);
  307. }
  308. });
  309. GUIUtils.setupAndShowDialog(
  310. elements,
  311. function()
  312. {
  313. var values = {};
  314. getinputs.forEach( function(gi) {gi(values);} );
  315. return values;
  316. },
  317. __TWO_BUTTONS,
  318. args['title'],
  319. callback);
  320. }
  321. else if( type == _ENTITY_EDITOR )
  322. /* args: uri */
  323. {
  324. var uri = (args['uri'] || __selection['items'][0]),
  325. matches = uri.match(/.*\/(.*)Icon\/(.*)\.instance/) ||
  326. uri.match(/.*\/(.*)Link\/(.*)\.instance/),
  327. type = matches[1],
  328. id = matches[2];
  329. HttpUtils.httpReq(
  330. 'GET',
  331. HttpUtils.url(uri),
  332. undefined,
  333. function(statusCode,resp)
  334. {
  335. if( ! utils.isHttpSuccessCode(statusCode) )
  336. return error(resp);
  337. return openDialog(
  338. _DICTIONARY_EDITOR,
  339. {'data': utils.jsonp( utils.jsonp(resp)['data'] ),
  340. 'ignoreKey':
  341. function(attr,val)
  342. {
  343. return attr.charAt(0) == '$' || val == undefined;
  344. },
  345. 'keepEverything':
  346. function()
  347. {
  348. return __changed(uri);
  349. },
  350. 'title':'edit '+type+' #'+id},
  351. callback || function(changes) {DataUtils.update(uri,changes);});
  352. });
  353. }
  354. else if( type == _ERROR )
  355. error(args);
  356. else if( type == __FATAL_ERROR )
  357. error(args,true);
  358. else if( type == _FILE_BROWSER )
  359. /* args: extensions,manualInput,title,startDir */
  360. {
  361. FileBrowser.buildFileBrowser(args['extensions'], args['manualInput'], args['title'], args['startDir'], callback);
  362. }
  363. else if( type == _LEGAL_CONNECTIONS )
  364. /* args: uri1, uri2, ctype, forceCallback */
  365. {
  366. var legalConnections = __legalConnections(args['uri1'],args['uri2'],args['ctype']);
  367. if( legalConnections.length == 0 )
  368. {
  369. var err = 'no valid connection between selected types';
  370. if( args['forceCallback'] )
  371. callback({'$err':err});
  372. else
  373. error(err);
  374. }
  375. else if( legalConnections.length == 1 )
  376. callback( legalConnections[0]+'Link.type' );
  377. else
  378. {
  379. var select = GUIUtils.getSelector(legalConnections);
  380. GUIUtils.setupAndShowDialog(
  381. [select],
  382. function() {return HttpUtils.getSelectorSelection(select)+'Link.type';},
  383. __TWO_BUTTONS,
  384. 'choose connection type',
  385. callback);
  386. }
  387. }
  388. else if( type == _LOADED_TOOLBARS )
  389. /* args: multipleChoice, type, title */
  390. {
  391. var choosableToolbars = [];
  392. for( var tb in __loadedToolbars )
  393. {
  394. if( (args['type'] == undefined &&
  395. (__isIconMetamodel(tb) || __isButtonModel(tb))) ||
  396. (args['type'] == 'metamodels' &&
  397. __isIconMetamodel(tb)) ||
  398. (args['type'] == 'buttons' &&
  399. __isButtonModel(tb)) )
  400. choosableToolbars.push(tb);
  401. }
  402. var select = GUIUtils.getSelector(choosableToolbars,args['multipleChoice']);
  403. GUIUtils.setupAndShowDialog(
  404. [select],
  405. function() {return HttpUtils.getSelectorSelection(select);},
  406. __TWO_BUTTONS,
  407. args['title'],
  408. callback);
  409. }
  410. else if( type == _DICTIONARY_EDITOR )
  411. /* args: data, ignoreKey, keepEverything, title */
  412. {
  413. var form = $('<form>'),
  414. table = $('<table>'),
  415. attrs2ii = {};
  416. form.onsubmit = function() {return false;};
  417. form.append(table);
  418. for( var attr in args['data'] )
  419. {
  420. if( args['ignoreKey'] != undefined &&
  421. args['ignoreKey'](attr,args['data'][attr]['value']) )
  422. continue;
  423. var tr = $('<tr>');
  424. tr.attr("id", "tr_" + attr);
  425. var ii = null;
  426. try {
  427. ii = GUIUtils.getInputField(
  428. args['data'][attr]['type'],
  429. args['data'][attr]['value']);
  430. } catch (err) {
  431. console.log(args['data'][attr]);
  432. WindowManagement.openDialog(
  433. _ERROR,
  434. 'unexpected error in editing mode ::\n ' + err + '\n' + utils.jsons(args['data'][attr]));
  435. }
  436. // var tr = table.append( $('<tr>') ),
  437. // ii = GUIUtils.getInputField(
  438. // args['data'][attr]['type'],
  439. // args['data'][attr]['value']);
  440. tr.append( $('<td>').append( GUIUtils.getTextSpan(attr)) );
  441. tr.append( $('<td>').append(ii.input) );
  442. if (ii.input.extra_el) tr.append( $('<td>').append(ii.input.extra_el) );
  443. attrs2ii[attr] = ii;
  444. table.append( tr );
  445. }
  446. GUIUtils.setupAndShowDialog(
  447. [form],
  448. function()
  449. {
  450. var changes = {},
  451. keepAll = (args['keepEverything'] != undefined &&
  452. args['keepEverything']());
  453. for( var attr in attrs2ii )
  454. {
  455. var am = attrs2ii[attr];
  456. var newVal = am['getinput'](am['input']);
  457. if( keepAll ||
  458. utils.jsons(newVal) != utils.jsons(am['oldVal']) )
  459. changes[attr] = newVal;
  460. }
  461. return changes;
  462. },
  463. __TWO_BUTTONS,
  464. args['title'],
  465. callback);
  466. }
  467. else if( type == __SVG_TEXT_EDITOR )
  468. {
  469. if( args.tagName != 'tspan' )
  470. {
  471. console.warn('SVG text editing only works on "Text" VisualObjects');
  472. return;
  473. }
  474. var vobj = args.parentNode,
  475. vobjuri = vobj.getAttribute('__vobjuri'),
  476. iconuri = __vobj2uri(vobj),
  477. lines = [];
  478. for( var i=0; i < vobj.children.length; i++ )
  479. if( vobj.children[i].tagName == 'tspan' )
  480. lines.push(vobj.children[i].textContent);
  481. var input =
  482. GUIUtils.getTextInput(
  483. lines.join('\n'),
  484. undefined,
  485. Math.min(lines.length,__MAX_TEXTAREA_LINES) );
  486. GUIUtils.setupAndShowDialog(
  487. [input],
  488. function() {return input.value;},
  489. __TWO_BUTTONS,
  490. 'enter new text',
  491. function(newVal)
  492. {
  493. DataUtils.update(
  494. iconuri+'/'+vobjuri+'.vobject',{'textContent':newVal});
  495. });
  496. }
  497. };
  498. /* spawn a new instance of atompm... if a model is specified (as 'fname'), it is
  499. loaded into the new instance... if a callback url is specified, critical
  500. information about the new instance is POSTed to it
  501. NOTE:: window.open returns a reference to the created window... however, this
  502. reference is not always complete (e.g. body.onload has not necessarily
  503. run its course)... for this reason, before proceeding with handling
  504. 'fname' and 'callbackURL', we poll the reference to ensure its
  505. completion */
  506. this.spawnClient = function (fname,callbackURL)
  507. {
  508. var c = window.open(window.location.href, '_blank'),
  509. onspawn =
  510. function()
  511. {
  512. if( (fname || callbackURL) &&
  513. (c.__wid == undefined ||
  514. c.__aswid == undefined ||
  515. c._loadModel == undefined) )
  516. return window.setTimeout(onspawn,250);
  517. c.__user = __user;
  518. if( fname )
  519. c._loadModel(fname);
  520. if( callbackURL )
  521. _httpReq(
  522. 'POST',
  523. callbackURL,
  524. {'aswid':c.__aswid,
  525. 'cswid':c.__wid,
  526. 'fname':fname,
  527. 'host':window.location.host});
  528. };
  529. onspawn();
  530. };
  531. /* NOTE:: Automating activities
  532. spawn a new instance of atompm... if a model is specified (as 'fname'), it is
  533. loaded into the new instance, if a toolbar is especified (as 'tbname'), it's loaded
  534. into the new instance, if a message is especified a popup message will show in
  535. the instance*/
  536. this.spawnClientOption = function (fname,tbname,option,trafo,msg)
  537. {
  538. var c = window.open(window.location.href, '_blank'),
  539. onspawn =
  540. function()
  541. {
  542. if( (fname|| tbname) &&
  543. (c.__wid == undefined ||
  544. c.__aswid == undefined ||
  545. c._loadModel == undefined ||
  546. c._loadToolbar == undefined) )
  547. return window.setTimeout(onspawn,250);
  548. c.__user = __user;
  549. c.__name = fname;
  550. c.__option = option;
  551. c.__trafo = trafo;
  552. c.__msg = msg;
  553. if (trafo == undefined){
  554. trafo = option;
  555. }
  556. if( tbname ){
  557. toolbars = tbname.split(",");
  558. for ( var n in toolbars){
  559. c._loadToolbar(toolbars[n]);
  560. }
  561. }
  562. if( fname ){
  563. c.__saveas = fname;
  564. if( option.length > 2 ){
  565. c._loadModel(fname);
  566. }
  567. }
  568. };
  569. onspawn();
  570. };
  571. /* initialize a headless client, i.e. a client with a proper backend but whose
  572. socket-message handling code is user-defined
  573. 1. setup new backend csworker and subscribe to it
  574. 2. call 'onready'
  575. 3. from this point on, all incoming socket messages are dispatched to
  576. 'onchlog'
  577. NOTE:: this code and the above comments are simplified versions of what's in
  578. initClient() (TBI:: merge this function with initClient()??)
  579. NOTE:: the context object gets populated with the headless client's wids and
  580. with a pointer to a function that closes it (as 'close') */
  581. this.spawnHeadlessClient = function (context,onready,onchlog)
  582. {
  583. var socket = io.connect(
  584. window.location.hostname,
  585. {'port':8124,'reconnect':false,'force new connection':true});
  586. socket.on('message',
  587. function(msg)
  588. {
  589. console.debug(' >>> '+utils.jsons(msg));
  590. if( msg['statusCode'] != undefined )
  591. {
  592. if( msg['statusCode'] == 201 )
  593. {
  594. HttpUtils.httpReq(
  595. 'PUT',
  596. '/aswSubscription?wid='+context.__wid,
  597. undefined,
  598. function(statusCode,resp)
  599. {
  600. context.__aswid = utils.jsonp(resp)['data'];
  601. onready();
  602. });
  603. context.close = socket.socket.disconnect;
  604. }
  605. else
  606. console.error('headless client failed to connect to back-end');
  607. }
  608. else
  609. onchlog(
  610. msg['data']['changelog'],
  611. msg['data']['sequence#'],
  612. msg['data']['hitchhiker']);
  613. });
  614. socket.on('disconnect',
  615. function()
  616. {
  617. console.debug('headless client lost connection to back-end');
  618. });
  619. socket.on('connect',
  620. function()
  621. {
  622. HttpUtils.httpReq(
  623. 'POST',
  624. '/csworker',
  625. undefined,
  626. function(statusCode,resp)
  627. {
  628. console.debug("Connect!");
  629. console.debug(statusCode);
  630. console.debug(resp);
  631. context.__wid = resp;
  632. socket.emit(
  633. 'message',
  634. {'method':'POST','url':'/changeListener?wid='+context.__wid});
  635. });
  636. });
  637. };
  638. /**
  639. * Sets whether to update the window title or not
  640. * @param changed whether or not the title has changed
  641. */
  642. this.setWindowTitle = function(changed)
  643. {
  644. if( __saveas == undefined )
  645. document.title =
  646. __TITLE +' - '+
  647. (changed ? '+ ' :'')+
  648. '[Unnamed]';
  649. else
  650. document.title =
  651. __TITLE+' - '+
  652. (changed ? '+ ' :'')+
  653. __saveas.match(/(.*\/){0,1}(.*)\.model/)[2]+' - '+
  654. __saveas;
  655. };
  656. /**
  657. * Displays the modal dialog
  658. */
  659. this.showDialog = function()
  660. {
  661. var dialog = __dialog_stack[__dialog_stack.length-1],
  662. dim_bg = $('#div_dim_bg');
  663. dim_bg.css("display", 'inline');
  664. dialog.css("display", 'block');
  665. dialog.css("left", document.body.scrollLeft +
  666. window.innerWidth/2 -
  667. dialog.width()/2 + "px");
  668. dialog.css("top", document.body.scrollTop +
  669. window.innerHeight/2 -
  670. dialog.height()/2 + "px");
  671. __setCanvasScrolling(false);
  672. };
  673. /**
  674. * Closes the modal dialog if it is currently opened (with arg js event)
  675. * Huseyin Ergin
  676. * HUSEYIN-ENTER
  677. */
  678. this.closeDialog = function(ev)
  679. {
  680. if(ev!=null && ev.keyCode==13) {
  681. $('#div_dialog_' + (__dialog_stack.length-1).toString() + " .okbutton").click();
  682. }
  683. __dialog_stack.pop();
  684. var dialog = $('#div_dialog_'+__dialog_stack.length);
  685. dialog.remove();
  686. if (!__dialog_stack.length) {
  687. __setCanvasScrolling(true);
  688. $('#div_dim_bg').css("display", 'none');
  689. BehaviorManager.setActiveBehaviourStatechart(__SC_CANVAS);
  690. }
  691. };
  692. return this;
  693. }();