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