📄 core.js.svn-base
字号:
/*Class: FlashSYS Translations, modules, loading functions etcCopyright: Copyright (C) 2008 OpenRB.comOptions: modulePath - (string) root directory for all modules moduleExt - (string) module file extensionProperties: menu - (object) main menu object with sections and modules menuSections - (object) main menu section element cache by name menuItems - (object) all main menu items (modules) cached by name translations - (object) translation hash elemCache - (object) module element cache (windows, table, forms, etc) loadingModules - (array) list of modules that are in loading state reloaders - (object) list of modules that can reload by timer loadBlock - (string) specifies which module has blocked loading for others blockAll - (boolean) global block on all AJAX requests idCounter - (integer) id counter for widget id generation changes - (object) queue for 'Apply changes' changesButton - (null or element) button element for 'Apply changes' extraModules - (object) cache of installed extra modules*/var FlashSYS = { menu: {}, menuSections: {}, menuItems: {}, translations: {}, elemCache: {}, loadingModules: [], reloaders: {}, loadBlock: '', blockAll: false, idCounter: 0, changes: {}, changesButton: null, extraModules: {}, options: { moduleRoot: '/cgi-bin/modules/', moduleExt: '.cgi' }, /* Function: translate Get value from translation hash or return the key Arguments: key - (string) key to lookup in translation hash table Returns: (string) translation for given key or the original key if value was not found */ translate: function(key) { return (this.translations[key.replace(/\W/g,'_')] || key); }, /* Function: requestUrl Get formatted request url from given object Arguments: params - (object) specific request parameters Returns: (string) request url */ requestUrl: function(params) { return this.options.moduleRoot + params.module + '/' + params.action + this.options.moduleExt; }, /* Function: getCache Get value from global cache Arguments: key - (string) key to lookup Returns: (object or false) cached object or false if none found */ getCache: function(key) { return this.elemCache[ key ] || false; }, /* Function: setCache Set / store item into global cache Arguments: key - (string) lookup key value - (object) object to cache Returns: (object) cached object */ setCache: function(key, value) { this.elemCache[ key ] = value; var menuItem = this.menuItems[ key ]; if (menuItem) { menuItem.addClass('Checked'); } return value; }, /* Function: isCached Checks if item with given key is cached Arguments: key - (string) lookup key Returns: (boolean) cache state */ isCached: function(key) { return !!this.elemCache[ key ]; }, /* Function: clearCache Removes item from cache Arguments: key - (string) lookup key */ clearCache: function(key) { var menuItem = this.menuItems[ key ]; if (menuItem) { menuItem.removeClass('Checked'); } delete this.elemCache[ key ]; delete this.reloaders[ key ]; }, /* Function: setReloader Register module as reloader Arguments: key - (string) lookup key */ setReloader: function(key) { this.reloaders[ key ] = $time(); }, /* Function: doReload Periodical module reload by timer */ doReload: function() { var moduleId = null; var reloadTime = 0; for (var curModule in this.reloaders) { // module is loading already, ignore if (this.loadingModules.contains(moduleId)) { continue; } var curTime = this.reloaders[ curModule ]; // no reload module set or last reload time is less than current if (!reloadTime || curTime < reloadTime) { moduleId = curModule; reloadTime = curTime; } } // module found, start reload if (moduleId) { this.reloaders[ moduleId ] = $time(); this.load({ module: moduleId }); } }, /* Function: newWindow Creates new window or returns instance it already exists Arguments: options - (object) new window options Returns: (options) new / existing window instance */ newWindow: function(options) { // id option is mandatory if (!options.id) { return false; } // width fix, magic number for now if (options.width) { options.width = Math.round(options.width.toInt() / 50) * 50 + 14; } return new MochaUI.Window(options); }, /* Function: closeWindow Closes window with given id Arguments: key - (string) lookup key */ closeWindow: function(key) { var elems = this.getCache(key); if (elems && elems.window) { MochaUI.closeWindow( elems.window.windowEl ); } }, notifyWindow: function() { var window = new MochaUI.Window({ type: 'notification', notifyText: Array.flatten(arguments).join('<br />'), padding: 10 }); }, /* Function: load loads module using Request by given params Arguments: params - (object) various parameters, see below Params: module - (string) module name action - (string) action, defaults to 'main' exec - (boolean) defaults to true, if specified: evaluates response data - (object) this data is passed to loading module as a JSON string checkInstance - (boolean) defaults to true, if specified: checks if requested module window is already open canReload - (boolean) defaults to true, if specified: execute load even if window is already open, adds 'reload': true parameter to data setBlock - (boolean) defaults to false, if specified: blocks calls to this function until blocking module is loaded success - (null or function) if specified: this function will be executed if / when module is loaded failure - (null or function) if specified: this function will be executed if / when module loading failed retFalse - (boolean) defaults to false, if specified: this function will always return false (usefull for binding to onclick event for links) reload - (null or string) module name to load after loading of given module is finished noEncode - (boolean) defaults to false, encode data using JSON or not Returns: (boolean) true if request was executed, false if some checks failed (depends on retFalse value) */ load: function(params) { // block is set, can't execute this function if (this.loadBlock !== '' || this.blockAll) { return false; } params = $merge({ module: 'default', action: null, exec: true, data: {}, checkInstance: true, canReload: true, setBlock: false, success: null, failure: null, retFalse: false, reload: false, noEncode: false }, params); if (params.action) { params.moduleId = params.module + '_' + params.action; } else { params.moduleId = params.module; params.action = 'main'; } if (params.setBlock) { this.loadBlock = params.moduleId; } // this module is already in loading state, no need to call this again if (this.loadingModules.contains(params.moduleId)) { return false; } // check for existing instance of this window if (params.checkInstance && this.isCached(params.moduleId)) { // instance exists and cannot be reloaded - focus window and exit if (!params.canReload) { // MochaUI.focusWindow(instance.windowEl); return false; } // add reload flag to data object else { params.data.reload = true; } } // send our ajax request var fsRequest = new Request({ 'url': this.requestUrl(params), 'data': { 'data': (params.noEncode ? params.data : JSON.encode(params.data)) }, 'extra': params, 'onSuccess': this.loadSuccess.bind(this), 'onFailure': this.loadFailed.bind(this, params) }).send(); return !params.retFalse; }, /* Function: loadSuccess Executed when got data from AJAX request without any error Arguments: responseText - (string) module response text xml - (string) xml response, not used params - (object) extra parameters from load function */ loadSuccess: function(responseText, xml, params) { // global block is set, ignore any action if (this.blockAll) { return; } // no action if module was in reload state but the window is already closed if (params.data.reload && !this.isCached(params.moduleId)) { this.loadingModules.erase(params.moduleIderase); return; } // execute custom success function for this module if ($type(params.success) == 'function') { params.success(responseText, params); } // execute response if (params.exec) { $exec(responseText); } this.loadFinished(params.moduleId); // reload another module, it must exist to be reloaded if (params.reload && this.isCached(params.reload)) { this.load({ module: params.reload }); } }, /* Function: loadFailed Executed when there was an error during load Arguments: params - (object) extra parameters from load function */ loadFailed: function(params) { // global block is set, ignore any action if (this.blockAll) { return; } if ($type(params.failure) == 'function') { params.failure(params); } this.loadFinished(params.moduleId); }, /* Function: loadFinished Executed in the end of loadSuccess and loadFailed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -