mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 10:45:47 +00:00
feature(files) add showError
This commit is contained in:
parent
e265214051
commit
d109ab625d
1 changed files with 34 additions and 18 deletions
|
|
@ -10,6 +10,8 @@ var Util, DOM;
|
|||
|
||||
function FilesProto(Util, DOM) {
|
||||
var Files = this,
|
||||
FILES_JSON = 'config|modules|ext',
|
||||
FILES_HTML = 'file|path|link|pathLink',
|
||||
funcs = [],
|
||||
Data = {},
|
||||
DIR_HTML = '/html/',
|
||||
|
|
@ -41,38 +43,52 @@ var Util, DOM;
|
|||
};
|
||||
|
||||
this.set = function(name, data, callback) {
|
||||
var strFiles = FILES_JSON + FILES_HTML,
|
||||
regExp = new RegExp(strFiles),
|
||||
isFile = regExp.match(regExp);
|
||||
|
||||
Util.checkArgs(arguments, [name, data]);
|
||||
|
||||
Data[name] = data;
|
||||
callback(null);
|
||||
if (!isFile) {
|
||||
showError(name);
|
||||
} else {
|
||||
Data[name] = data;
|
||||
callback(null);
|
||||
}
|
||||
|
||||
return Files;
|
||||
};
|
||||
|
||||
function getModule(name, callback) {
|
||||
var path,
|
||||
json = 'config|modules|ext',
|
||||
html = 'file|path|link|pathLink',
|
||||
|
||||
regExpHTML = new RegExp(html),
|
||||
regExpJSON = new RegExp(json),
|
||||
regExpHTML = new RegExp(FILES_HTML),
|
||||
regExpJSON = new RegExp(FILES_JSON),
|
||||
|
||||
isHTML = name.match(regExpHTML),
|
||||
isJSON = name.match(regExpJSON);
|
||||
|
||||
if (isHTML) {
|
||||
path = DIR_HTML_FS + name + '.html',
|
||||
getSystemFile(Data[name], path , callback);
|
||||
} else if (isJSON) {
|
||||
if (name === 'config') {
|
||||
getConfig(callback);
|
||||
} else {
|
||||
path = DIR_JSON + name + '.json';
|
||||
getSystemFile(Data[name], path, callback);
|
||||
if (!isHTML && !isJSON)
|
||||
showError(name);
|
||||
else
|
||||
if (isHTML) {
|
||||
path = DIR_HTML_FS + name + '.html',
|
||||
getSystemFile(Data[name], path , callback);
|
||||
} else if (isJSON) {
|
||||
if (name === 'config') {
|
||||
getConfig(callback);
|
||||
} else {
|
||||
path = DIR_JSON + name + '.json';
|
||||
getSystemFile(Data[name], path, callback);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw(new Error('Wrong file name: ' + name));
|
||||
}
|
||||
}
|
||||
|
||||
function showError(name) {
|
||||
var str = 'Wrong file name: ' + name,
|
||||
error = new Error(str);
|
||||
|
||||
throw(error);
|
||||
}
|
||||
|
||||
function getSystemFile(global, url, callback) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue