/* This file is part of AToMPM - A Tool for Multi-Paradigm Modelling * Copyright 2011 by the AToMPM team and licensed under the LGPL * See COPYING.lesser and README.md in the root of this project for full details */ GUIUtils = function(){ /** * This is the old getElementById function */ this.$$ = function( id ){ return document.getElementById( id ); }; /** * Converts from page centric X coordinates to canvas centric X coordinates */ this.convertToCanvasX = function(pageX){ return pageX + $('#div_container').scrollLeft() - $('#contentDiv').offset().left; }; /** * Converts from page centric Y coordinates to canvas centric Y coordinates */ this.convertToCanvasY = function(pageY){ return pageY + $('#div_container').scrollTop() - $('#contentDiv').offset().top; }; /** * Disables the dock bar */ this.disableDock = function(){ $('#div_dock').attr('class', 'dock disabled_dock'); }; /** * Enables the dock bar */ this.enableDock = function(){ $('#div_dock').attr('class', 'dock'); }; /** * Constructs and returns a checked checkbox */ this.getCheckbox = function(checked){ var cb = $(''); cb.attr("type", 'checkbox'); cb.prop("checked", checked); return cb; }; /** * Returns a
with an interactive file browser within it * * @param fnames - a complete list of all files in the directory tree * structure * @param draggable - when true, files and folders can be meaningfully * dragged * @param newfile when true, an editable new file icon is present * @param startfolder if set, starts navigation at the specified folder */ this.getFileBrowser = function(fnames, draggable, newfile, startfolder){ var maxFnameLength = utils.max(fnames,function(_) {return _.length;}), fileb = $("
"), navdiv = $("
"), input = $(""), selection = undefined, currfolder = '/', clearSelection = function() { if( selection ) { selection.attr("class", 'fileb_icon'); selection = undefined; input.val(''); } }, navbuttononclick = /* 1 construct the full path associated to the clicked button 2 remove 'deeper' buttons 3 chdir to selected folder */ function(ev) { var path = ''; for( var i=0; i 0 ) { $('#div_fileb-contents').remove(); // exists = true; } div = $("
"); div.attr("class", 'fileb_pane') .attr("id", 'div_fileb-contents'); fnames.forEach( function(fname) { var _folder = utils.regexpe(folder); if( (matches=fname.match('^'+_folder+'(.+?/)')) ) { if( ! utils.contains(folders,matches[1]) ) folders.push(matches[1]); else return; } else if( (matches=fname.match('^'+_folder+'(.*)')) ) { if (matches[1].length > 0) { files.push(matches[1]); } else { return; } } else return; maxFnameLength = Math.max(maxFnameLength,matches[1].length); }); // var tmpDiv = $("
"); folders.concat(files).forEach( function(fname) { var icon = HttpUtils.getFileIcon(fname); if( icon ) { icon.css("width", 8+maxFnameLength+'ex'); icon.click( function(ev) { clearSelection(); if( fname.match(/\/$/) ) setCurrentFileBrowserFolder(folder+fname,fnames); else { input.val( folder+fname ); selection = icon; selection.attr("class", 'fileb_icon_selected'); } }); if( draggable ) { //icon.setAttribute('draggable',true); icon.attr("draggable", true); icon.get(0).ondragstart = function(event) { var uri = HttpUtils.url(folder+fname+'.file',__NO_WID); event.dataTransfer.effectAllowed = 'copyMove'; event.dataTransfer.setData( 'DownloadURL', 'application/zip:'+fname+'.zip:'+ window.location.origin+uri); event.dataTransfer.setData('uri',uri); }; } div.append(icon); } }); if( newfile ) { var icon = HttpUtils.getNewFileIcon( function(ev) { input.val( folder+ev.target.textContent ); }); icon.css("width", 8+maxFnameLength+'ex'); div.append(icon); } navdiv.empty(); // while (navdiv.children().length > 0) { // navdiv.find(navdiv.lastChild).remove(); // } tmpDiv = $("
"); var subfolders = folder.split('/').filter(function(subf) {return subf != '';}); subfolders.unshift('/'); subfolders.forEach(function(subfolder) { var navbutton = $('