⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.js

📁 在线编辑器
💻 JS
📖 第 1 页 / 共 2 页
字号:
        var project = project || '';        var path = path || '';        var url = bespin.util.path.combine('/file/at', project, path);        this.request('GET', url, null, { call: callback });    },    // ** {{{ removeFile(project, path, onSuccess, onFailure) }}}    //    // Remove the given file    //     // * {{{project}}} is the project to remove from    // * {{{path}}} is the path to remove    // * {{{onSuccess}}} fires if the deletion works    // * {{{onFailure}}} fires if the deletion failed    removeFile: function(project, path, onSuccess, onFailure) {        var project = project || '';        var path = path || '';        var url = bespin.util.path.combine('/file/at', project, path);        var opts = { call: onSuccess };        if (dojo.isFunction(onFailure)) opts.onFailure = onFailure;                this.request('DELETE', url, null, opts);    },    // ** {{{ makeDirectory(project, path, onSuccess, onFailure) }}}    //    // Create a new directory    //     // * {{{project}}} is the project to save    // * {{{path}}} is the path to save to    // * {{{onSuccess}}} fires if the deletion works    // * {{{onFailure}}} fires if the deletion failed    makeDirectory: function(project, path, onSuccess, onFailure) {        if (!project) return;        var url = bespin.util.path.combineAsDirectory('/file/at', project, (path || ''));        var opts = {};        if (dojo.isFunction(onSuccess)) {            opts.call = onSuccess;        } else {            opts['log'] = "Made a directory: [project=" + project + ", path=" + path + "]";        }        if (dojo.isFunction(onFailure)) opts.onFailure = onFailure;        this.request('PUT', url, null, opts);    },        // ** {{{ removeDirectory(project, path, onSuccess, onFailure) }}}    //    // Removed a directory    //     // * {{{project}}} is the project to save    // * {{{path}}} is the path to save to    // * {{{onSuccess}}} fires if the deletion works    // * {{{onFailure}}} fires if the deletion failed    removeDirectory: function(project, path, onSuccess, onFailure) {        if (!project) return;        if (!path) path = '';                var url = bespin.util.path.combineAsDirectory('/file/at', project, path);        var opts = {};        if (dojo.isFunction(onSuccess)) {            opts.call = onSuccess;        } else {            opts['log'] = "Removed directory: [project=" + project + ", path=" + path + "]";        }        if (dojo.isFunction(onFailure)) opts.onFailure = onFailure;        this.request('DELETE', url, null, opts);    },     // ** {{{ listOpen(callback) }}}     //     // Returns JSON with the key of filename, and the value of an array of usernames:     // { "foo.txt": ["ben"], "SomeAjaxApp/foo.txt": ["dion"] }     //      // * {{{callback}}} fires after listing the open files    listOpen: function(callback) {        this.request('GET', '/file/listopen/', null, {            call: callback, evalJSON: true, log: 'List open files.'         });    },    // ** {{{ closeFile(project, path, callback) }}}    //    // Close the given file (remove from open sessions)    //     // * {{{project}}} is the project to close from    // * {{{path}}} is the path to close    // * {{{callback}}} fires after the file is closed    closeFile: function(project, path, callback) {        var path = path || '';        var url = bespin.util.path.combine('/file/close', project, path);        this.request('POST', url, null, { call: callback });    },    // == EDIT ==    // ** {{{ editActions(project, path, callback) }}}    //    // Get the list of edit actions    //     // * {{{project}}} is the project to edit from    // * {{{path}}} is the path to edit    // * {{{callback}}} fires after the edit is done    editActions: function(project, path, callback) {        var path = path || '';        var url = bespin.util.path.combine('/edit/list', project, path);        this.request('GET', url, null, { call: callback, log: "Edit Actions Complete." });    },    // ** {{{ editAfterActions(project, path, callback) }}}    //    // Get the list of edit after actions    //     // * {{{project}}} is the project to edit from    // * {{{path}}} is the path to edit    // * {{{callback}}} fires after the edit is done    editAfterActions: function(project, path, index, callback) {        var path = path || '';        var url = bespin.util.path.combine('/edit/recent', index, project, path);        this.request('GET', url, null, { call: callback, log: "Edit After Actions Complete." });    },    // ** {{{ doAction(project, path, actions) }}}    //    // Store actions to the edit queue    //     // * {{{project}}} is the project    // * {{{path}}} is the path    // * {{{actions}}} contain the actions to store    doAction: function(project, path, actions) {        var path = path || '';        var url = bespin.util.path.combine('/edit', project, path);        var sp = "[" + actions.join(",") + "]";        this.request('PUT', url, sp, { call: function(){} });    },    // == PROJECTS ==    //    // still needed: owners, authorize, deauthorize        // ** {{{ exportProject(project, archivetype) }}}    //    // Export the project as either a zip file or tar + gz    //     // * {{{project}}} is the project to export    // * {{{archivetype}}} is either zip | tgz    exportProject: function(project, archivetype) {        if (bespin.util.include(['zip','tgz','tar.gz'], archivetype)) {            var iframe = document.createElement("iframe");            iframe.src = bespin.util.path.combine('/project/export', project + "." + archivetype);            iframe.style.display = 'none';            iframe.style.height = iframe.style.width = "0";            document.getElementsByTagName("body")[0].appendChild(iframe);        }    },    // ** {{{ importProject(project, url, opts) }}}    //    // Import the given file into the given project    //     // * {{{project}}} is the project to export    // * {{{url}}} is the URL to the file to import    // * {{{archivetype}}} is either zip | tgz    importProject: function(project, url, opts) {        if (opts) { // wrap the import success call in an event to say that the import is complete            var userCall = opts.call;            opts.call = function(text, xhr) {                userCall(text, xhr);                document.fire("bespin:project:imported", {                    project: project,                    url: url                });            }        }                this.request('POST', '/project/fromurl/' + project, url, opts || {});    },        // ** {{{ renameProject(currentProject, newProject) }}}    //    // Import the given file into the given project    //     // * {{{currentProject}}} is the current name of the project    // * {{{newProject}}} is the new name    renameProject: function(currentProject, newProject, opts) {        if (!opts) opts = { log: "Renaming project from " + currentProject + " to " + newProject };        if (currentProject && newProject) {            this.request('POST', '/project/rename/' + currentProject + "/", newProject, opts);        }    },    // == SETTINGS ==    //    //    // * GET /settings/ to list all settings for currently logged in user as json dict    // * GET /settings/[setting] to get the value for a single setting as json string    // * POST /settings/ with HTTP POST DATA (in standard form post syntax) to set the value for a collection of settings (all values are strings)    // * DELETE /settings/[setting] to delete a single setting    listSettings: function(callback) {        if (typeof callback == "function") {            this.request('GET', '/settings/', null, { call: callback, evalJSON: true });        }    },    getSetting: function(name, callback) {        if (typeof callback == "function") {            this.request('GET', '/settings/' + name, null, { call: callback });        }    },        setSetting: function(name, value, callback) {        var settings = {};        settings[name] = value;        this.setSettings(settings, (callback || function(){}));    },        setSettings: function(settings, callback) {        this.request('POST', '/settings/', dojo.objectToQuery(settings), { call: (callback || function(){}) });    },        unsetSetting: function(name, callback) {        this.request('DELETE', '/settings/' + name, null, { call: (callback || function(){}) });    }});

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -