FileDialog = { locked : false, lock : function () { if (FileDialog.locked) return false; FileDialog.locked=true; return true; }, unlock : function () { FileDialog.locked=false }, refreshFileDialog : function (handle) { var lastselect; console.log('refreshFileDialog',handle.dir); handle.list(handle.dir, function (res) { if (Utils.isError(res)) { return handle.onerror(res); } var input=$('#fileDialogListFileName'); if (res && res.status==0) { var list = $('#fileDialogList'); list.empty(); var entries=res.dirs; if (handle.mode=='Open' || handle.mode=='Load') entries=entries.concat(res.files); $('#fileDialogListLabel').html(handle.dir); entries.forEach(function (entry) { if (entry.name[0]=='.' && entry.name!='..') return; var listentry = $('

',{ class:'nav-entry '+(entry.dir?'nav-entry-directory':'nav-entry-file'), style:'cursor: pointer' }).append(''+entry.name+'').appendTo(list); if (entry.dir) listentry.bind('click',function () { if (entry.name=='..') handle.dir = handle.dir.replace(/(\/[^\/]+)$/,''); else handle.dir += ((handle.dir=='/'?'':'/')+entry.name); handle.dir=handle.dir||'/'; handle.selected=entry.name; FileDialog.refreshFileDialog(handle); }); else { listentry.bind('click',function () { if (lastselect) $(lastselect).removeClass('nav-selected'); $(listentry).addClass('nav-selected'); lastselect=listentry; handle.selected=entry.name; input.val(entry.name); }); } return entry; }) } }) }, dialog : function (title, mode, dir, filename, fs, callback) { if (!FileDialog.lock()) return; var handle={selected:filename, dir:dir, mode:mode, list:fs.list}; var html='

'+title+ '

'; html += ''; html += '
'; html += '
'; var input,options handle.onerror=function (err) { // Fallback: Browser file dialog console.log('dialog',err); options.close(); FileDialog.unlock(); if (callback) callback(null,null,err); }; setTimeout(function () { FileDialog.refreshFileDialog(handle); input=$('#fileDialogListFileName'); },1); popup.custom(options={content:html,default_btns:{ok:mode}},function (reply) { FileDialog.unlock(); if (reply.proceed) { filename=input.val(); if (callback) callback(handle.dir,filename); } }); }, } if (!Config.wex) Config.wex={http:'http://localhost:11111' }; if (!Config.workdir) Config.workdir='/'; // FS APi using the WEX server FS = { list : async function (dir,cb) { var result; function handler (response) { if (Utils.isError(response)) { if (cb) cb(response); return; } if (!Utils.isObject(response) || response.status!=0) { result=response; if (cb) cb(result); return; } var dirs=response.reply.filter(function (entry) { return entry.dir }) .sort(function (a,b) { return a.name