lots of changes because goodies are now called file (and the prototypes have been renamed)
This commit is contained in:
parent
10dfb1d116
commit
072614bacf
1 changed files with 49 additions and 48 deletions
|
@ -1,53 +1,54 @@
|
||||||
/**
|
/**
|
||||||
* function checks if goodie fits to the minimal needs
|
* function checks if file fits to the minimal needs
|
||||||
* @param Obj Object containing the properties needed for creating a new goodie
|
* @param Obj Object containing the properties needed for creating a new file
|
||||||
* @param Obj User-Object creating this goodie
|
* @param Obj User-Object creating this file
|
||||||
* @return Obj Object containing two properties:
|
* @return Obj Object containing two properties:
|
||||||
* - error (boolean): true if error happened, false if everything went fine
|
* - error (boolean): true if error happened, false if everything went fine
|
||||||
* - message (String): containing a message to user
|
* - message (String): containing a message to user
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function evalGoodie(param,creator) {
|
function evalFile(param,creator) {
|
||||||
var result;
|
var result;
|
||||||
if (param.uploadError) {
|
if (param.uploadError) {
|
||||||
// looks like the file uploaded has exceeded uploadLimit ...
|
// looks like the file uploaded has exceeded uploadLimit ...
|
||||||
result = getError("goodieFileTooBig");
|
result = getError("fileFileTooBig");
|
||||||
} else if (param.rawgoodie) {
|
} else if (param.rawfile) {
|
||||||
if (param.rawgoodie.contentLength == 0) {
|
if (param.rawfile.contentLength == 0) {
|
||||||
// looks like nothing was uploaded ...
|
// looks like nothing was uploaded ...
|
||||||
result = getError("goodieNoUpload");
|
result = getError("fileNoUpload");
|
||||||
} else {
|
} else {
|
||||||
var newGoodie = new goodie();
|
var newFile = new file();
|
||||||
// store extension of uploaded goodie in variable
|
// store extension of uploaded file in variable
|
||||||
if (param.rawgoodie.name.lastIndexOf(".") > 0)
|
if (param.rawfile.name.lastIndexOf(".") > 0)
|
||||||
var fileExt = param.rawgoodie.name.substring(param.rawgoodie.name.lastIndexOf("."));
|
var fileExt = param.rawfile.name.substring(param.rawfile.name.lastIndexOf("."));
|
||||||
// first, check if alias already exists
|
// first, check if alias already exists
|
||||||
if (!param.alias)
|
if (!param.alias)
|
||||||
result = getError("goodieNameMissing");
|
result = getError("fileNameMissing");
|
||||||
else if (this.get(param.alias))
|
else if (this.get(param.alias))
|
||||||
result = getError("goodieExisting");
|
result = getError("fileExisting");
|
||||||
else if (!isClean(param.alias))
|
else if (!isClean(param.alias))
|
||||||
result = getError("noSpecialChars");
|
result = getError("noSpecialChars");
|
||||||
else if (!fileExt)
|
else if (!fileExt)
|
||||||
result = getError("fileInvalidExtension");
|
result = getError("fileInvalidExtension");
|
||||||
else {
|
else {
|
||||||
// store properties necessary for goodie-creation
|
// store properties necessary for file-creation
|
||||||
newGoodie.alias = param.alias;
|
newFile.alias = param.alias;
|
||||||
newGoodie.alttext = param.alttext;
|
newFile.site = this._parent;
|
||||||
newGoodie.file = param.alias + fileExt;
|
newFile.alttext = param.alttext;
|
||||||
newGoodie.filesize = param.rawgoodie.contentLength;
|
newFile.name = param.alias + fileExt;
|
||||||
newGoodie.mimetype = param.rawgoodie.contentType;
|
newFile.filesize = param.rawfile.contentLength;
|
||||||
newGoodie.description = param.description;
|
newFile.mimetype = param.rawfile.contentType;
|
||||||
var saveTo = getProperty("goodiePath") + this._parent.alias + "/";
|
newFile.description = param.description;
|
||||||
|
var saveTo = getProperty("filePath") + this._parent.alias + "/";
|
||||||
// any errors?
|
// any errors?
|
||||||
if (param.rawgoodie.writeToFile(saveTo,newGoodie.file)) {
|
if (param.rawfile.writeToFile(saveTo,newFile.name)) {
|
||||||
// the goodie is on disk, so we add the goodie-object
|
// the file is on disk, so we add the file-object
|
||||||
newGoodie.creator = creator;
|
newFile.creator = creator;
|
||||||
newGoodie.createtime = new Date();
|
newFile.createtime = new Date();
|
||||||
if (this.add(newGoodie)) {
|
if (this.add(newFile)) {
|
||||||
result = getConfirm("goodieCreate",newGoodie.alias);
|
result = getConfirm("fileCreate",newFile.alias);
|
||||||
} else
|
} else
|
||||||
result = getError("goodieCreate",newGoodie.alias);
|
result = getError("fileCreate",newFile.alias);
|
||||||
} else
|
} else
|
||||||
result = getError("fileSave");
|
result = getError("fileSave");
|
||||||
}
|
}
|
||||||
|
@ -58,44 +59,44 @@ function evalGoodie(param,creator) {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* alias of goodie has changed, so we remove it and add it again with it's new alias
|
* alias of file has changed, so we remove it and add it again with it's new alias
|
||||||
* @param Obj goodie-object whose alias should be changed
|
* @param Obj file-object whose alias should be changed
|
||||||
* @param String new alias of goodie
|
* @param String new alias of file
|
||||||
* @return Boolean true in any case ...
|
* @return Boolean true in any case ...
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function changeAlias(currGoodie,newAlias) {
|
function changeAlias(currFile,newAlias) {
|
||||||
this.remove(currGoodie);
|
this.remove(currFile);
|
||||||
this.set(currGoodie.alias,null);
|
this.set(currFile.alias,null);
|
||||||
currGoodie.alias = newAlias.alias;
|
currFile.alias = newAlias.alias;
|
||||||
this.add(currGoodie);
|
this.add(currFile);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* delete a goodie
|
* delete a file
|
||||||
* @param Obj goodie-object to delete
|
* @param Obj file-object to delete
|
||||||
* @return String Message indicating success or failure
|
* @return String Message indicating success or failure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function deleteGoodie(currGoodie) {
|
function deleteFile(currFile) {
|
||||||
// first remove the goodie from disk
|
// first remove the file from disk
|
||||||
var f = new File(getProperty("goodiePath") + currGoodie.weblog.alias, currGoodie.file);
|
var f = new File(getProperty("filePath") + currFile.site.alias, currFile.name);
|
||||||
f.remove();
|
f.remove();
|
||||||
if (this.remove(currGoodie))
|
if (this.remove(currFile))
|
||||||
return (getMsg("confirm","goodieDelete"));
|
return (getMsg("confirm","fileDelete"));
|
||||||
else
|
else
|
||||||
return (getMsg("error","goodieDelete"));
|
return (getMsg("error","fileDelete"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* function deletes all goodies
|
* function deletes all files
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function deleteAll() {
|
function deleteAll() {
|
||||||
for (var i=this.size();i>0;i--) {
|
for (var i=this.size();i>0;i--) {
|
||||||
var goodie = this.get(i-1);
|
var f = this.get(i-1);
|
||||||
this.deleteGoodie(goodie);
|
this.deleteFile(f);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue