/******************************************************************************* AToMPM - A Tool for Multi-Paradigm Modelling Copyright (c) 2011 Raphael Mannadiar (raphael.mannadiar@mail.mcgill.ca) Modified by Conner Hansen (chansen@crimson.ua.edu) This file is part of AToMPM. AToMPM is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. AToMPM is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with AToMPM. If not, see . *******************************************************************************/ /////////////////////////////////////////////////////////////////////////////// // DEPRECATED FUNCTIONS /////////////////////////////////////////////////////////////////////////////// function _openDialog(type, args, callback){ AtomPMClient.alertDeprecatedFunctionCall("_openDialog"); WindowManagement.openDialog(type, args, callback); } function _spawnClient(fname,callbackURL){ AtomPMClient.alertDeprecatedFunctionCall("_spawnClient"); WindowManagement.spawnClient(fname, callbackURL); } function _spawnHeadlessClient(context,onready,onchlog){ AtomPMClient.alertDeprecatedFunctionCall("_spawnHeadlessClient"); WindowManagement.spawnHeadlessClient(context, onready, onchlog); } function __showDialog(){ alert(AtomPMClient); AtomPMClient.alertDeprecatedFunctionCall("__showDialog"); WindowManagement.showDialog(); } function __closeDialog(){ AtomPMClient.alertDeprecatedFunctionCall("__closeDialog"); WindowManagement.closeDialog(); } /////////////////////////////////////////////////////////////////////////////// //DEPRECATED FUNCTIONS /////////////////////////////////////////////////////////////////////////////// var __dialog_stack = []; WindowManagement = function(){ /** * Hides the login screen */ this.hideLoginScreen = function() { //$('#div_login').style.display = 'none'; $('#div_login').css('display', 'none'); __setCanvasScrolling(true); }; /** * Shows the login screen */ this.showLoginScreen = function() { //$('#div_login').style.display = 'inline'; $('#div_login').css('display', 'inline'); __setCanvasScrolling(false); }; //Todo: Shred this function into smaller functions, as this should // really just amount to a switch statement //TBI: complete comments about each dialog (copy from user's manual) /** * Opens a general dialog window */ this.openDialog = function(type,args,callback) { args = args || {}; function error(err,fatal) { console.error("Error! " + err); GUIUtils.setupAndShowDialog( [GUIUtils.getTextSpan( err, 'error')], undefined, (fatal ? __NO_BUTTONS : __ONE_BUTTON), (fatal ? 'FATAL ERROR (restart required)' : 'ERROR')); //console.error(err,args); } // TODO: Fix this, convert to JQuery if( type == _CLOUD_DATA_MANAGER ) /* args: extensions,readonly,title */ { HttpUtils.httpReq( 'GET', HttpUtils.url('/filelist',__NO_WID), undefined, function(statusCode,resp){ var fnames = __localizeFilenames( __filterFilenamesByExtension( resp.split('\n'), args['extensions'] || ['.*'])).sort(), maxFnameLength = utils.max(fnames, function(_) { return _.length; }), fileb = GUIUtils.getFileBrowser(fnames,true), feedbackarea = $('
'), feedback = GUIUtils.getTextSpan(''), progressbar = $('
'), progressfill = $('
'), download = $('
'), trash = $('
'), div_dldel = $('
'), hldropzone = /* highlight or unhighlight the dropzone */ function(zone) { if( zone == undefined ) { fileb['filepane']().attr('class', 'fileb_pane'); download.attr('class', 'dropzone'); trash.attr('class', 'dropzone'); } else if( zone == 'upload' ) { var filepane = fileb['filepane'](); filepane.attr('class', 'fileb_pane droppable'); filepane.get(0).ondrop = onfilepanedrop; } else if( zone == 'dl/del' ) { download.attr('class', 'dropzone droppable'); trash.attr('class', 'dropzone droppable'); } }, cancelevt = /* prevent event bubbling */ function(event) { event.stopPropagation(); event.preventDefault(); return false; }, ondownloaddrop = function(event) { cancelevt(event); hldropzone(); window.location.assign(event.dataTransfer.getData('uri')); }, ontrashdrop = function(event) { cancelevt(event); hldropzone(); var uri = event.dataTransfer.getData('uri'); DataUtils.deleteFromCloud(uri, function(statusCode,resp) { if( ! utils.isHttpSuccessCode(statusCode) ) return error(resp); feedback.html('deleted '+uri.match(/.*\/(.+)\.file/)[1]); }); }, onfilepanedrop = /* react to file drop from desktop 1. exit with error if non-zip files 2. move to handleFiles() otherwise */ function(event) { cancelevt(event); hldropzone(); var files = event.dataTransfer.files; for( var i=0; i= files.length) return; var file = files[i]; feedback.html('uploading '+file.name); progressbar.css("display", 'inline-block'); var reader = new FileReader(); reader.onprogress = function(event) { if( event.lengthComputable ) progressfill.css("width", (100*event.loaded/event.total)+'%'); }; reader.onload = function(event) { progressfill.css("width", '100%'); feedback.html('processing '+file.name+' ...'); progressbar.css("display", 'none'); DataUtils.uploadToCloud( fileb['getcurrfolder'](), event.target.result, function(statusCode,resp) { if( ! utils.isHttpSuccessCode(statusCode) ) return error(resp); feedback.html('successfully processed '+file.name); handleFiles(files,++i); }); }; reader.readAsBinaryString(file); }, cloudmgrClosed = function() { return fileb['filebrowser'].parent() == null; }; document.body.ondragenter = /* show dropzone when file drag from desktop enters window */ function(event) { if(cloudmgrClosed()) return true; cancelevt(event); hldropzone( (event.dataTransfer.effectAllowed == 'copyMove' ? 'dl/del' : 'upload')); return false; }; document.body.ondragleave = /* hide dropzone when file drag from desktop leaves window (which causes event.pageX == 0) */ function(event) { if(cloudmgrClosed()) return true; cancelevt(event); if( event.pageX == 0 ) hldropzone(); return false; }; document.body.ondrop = function(event) { if(cloudmgrClosed()) return true; cancelevt(event); hldropzone(); console.warn('non-dropzone drops are ignored'); return false; }; fileb['filebrowser'].attr('title', 'drag\'n\'drop files to file pane to upload\n'+ '(close and re-open dialog to observe effects)'); download.attr('title', 'drag\'n\'drop files from file pane to download'); trash.attr('title', 'drag\'n\'drop files from file pane to delete\n'+ '(close and re-open dialog to observe effects)'); progressfill.attr('class', 'progress_fill'); progressfill.html(' '); progressbar.attr('class', 'progress_bar'); progressbar.append(progressfill); progressbar.css("display", 'none'); feedbackarea.append(feedback); feedbackarea.append(progressbar); download.css("backgroundImage", 'url(client/media/download.png)'); trash.css("backgroundImage", 'url(client/media/trash.png)'); download.attr('class', 'dropzone'); trash.attr('class', 'dropzone'); download.css("cssFloat", 'left'); trash.css("cssFloat", 'right'); download.get(0).ondragover = cancelevt; trash.get(0).ondragover = cancelevt; download.get(0).ondrop = ondownloaddrop; trash.get(0).ondrop = ontrashdrop; div_dldel.append(download); div_dldel.append(trash); if( args['readonly'] ) trash.css("display", 'none'); GUIUtils.setupAndShowDialog( [fileb['filebrowser'],div_dldel,feedbackarea], undefined, __ONE_BUTTON, args['title'] || 'manage your cloud data\n(note:: you must close and re-open '+ 'dialog to view upload and deletion effects)'); }); } else if( type == _CUSTOM ) /* args: widgets, title 'widgets' must be a list where each entry is either ['id':___,'type':'input','label':___,'default':___], or ['id':___,'type':'select','choices':___,'multipleChoice':___] */ { var elements = [], getinputs = []; args['widgets'].forEach( function(w) { if( w['type'] == 'select' ) { var select = GUIUtils.getSelector(w['choices'],w['multipleChoice']); getinputs.push(function(_) { _[w['id']] = HttpUtils.getSelectorSelection(select); }); elements.push(select); } else if( w['type'] == 'input' ) { var label = GUIUtils.getTextSpan(w['label'] || ''), input = GUIUtils.getStringInput(w['default'] || ''); getinputs.push(function(_) { _[w['id']] = input[0].value; }); elements.push(label,input); } }); GUIUtils.setupAndShowDialog( elements, function() { var values = {}; getinputs.forEach( function(gi) {gi(values);} ); return values; }, __TWO_BUTTONS, args['title'], callback); } else if( type == _ENTITY_EDITOR ) /* args: uri */ { var uri = (args['uri'] || __selection['items'][0]), matches = uri.match(/.*\/(.*)Icon\/(.*)\.instance/) || uri.match(/.*\/(.*)Link\/(.*)\.instance/), type = matches[1], id = matches[2]; HttpUtils.httpReq( 'GET', HttpUtils.url(uri), undefined, function(statusCode,resp) { if( ! utils.isHttpSuccessCode(statusCode) ) return error(resp); return openDialog( _DICTIONARY_EDITOR, {'data': utils.jsonp( utils.jsonp(resp)['data'] ), 'ignoreKey': function(attr,val) { return attr.charAt(0) == '$' || val == undefined; }, 'keepEverything': function() { return __changed(uri); }, 'title':'edit '+type+' #'+id}, callback || function(changes) {DataUtils.update(uri,changes);}); }); } else if( type == _ERROR ) error(args); else if( type == __FATAL_ERROR ) error(args,true); else if( type == _FILE_BROWSER ) /* args: extensions,multipleChoice,manualInput,title,startDir */ { HttpUtils.httpReq( 'GET', HttpUtils.url('/filelist',__NO_WID), undefined, function(statusCode,resp) { args['extensions'].push('/'); var fnames = __localizeFilenames( __filterFilenamesByExtension( resp.split('\n'), args['extensions'] || ['.*']) ).sort(), maxFnameLength = utils.max(fnames,function(_) {return _.length;}), folder_buttons = $('
'), new_folder_b = $('