antville/code/FileMgr/objectFunctions.js

94 lines
3.6 KiB
JavaScript
Raw Normal View History

2001-11-03 09:17:41 +00:00
/**
* 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
* @return Obj Object containing two properties:
* - error (boolean): true if error happened, false if everything went fine
* - message (String): containing a message to user
2001-11-03 09:17:41 +00:00
*/
function evalGoodie(param,creator) {
var result = new Object();
result.error = true;
2001-11-03 09:17:41 +00:00
if (param.uploadError) {
2001-11-03 09:17:41 +00:00
// looks like the file uploaded has exceeded uploadLimit ...
result.message = "File is too big to handle!";
} else if (param.rawgoodie) {
if (param.rawgoodie.contentLength == 0) {
2001-11-03 09:17:41 +00:00
// looks like nothing was uploaded ...
result.message = "Please upload a goodie and fill out the form ...";
2001-11-03 09:17:41 +00:00
} else {
var newGoodie = new goodie();
2001-11-03 09:17:41 +00:00
// store extension of uploaded goodie in variable
if (param.rawgoodie.name.lastIndexOf(".") > 0)
var fileExt = param.rawgoodie.name.substring(param.rawgoodie.name.lastIndexOf("."));
2001-11-03 09:17:41 +00:00
// first, check if alias already exists
if (!param.alias)
result.message = "You must enter a name for this goodie!";
else if (this.get(param.alias))
result.message = "There is already a goodie with this name!";
else if (!isClean(param.alias))
result.message = "Please do not use special characters in the name!";
2001-11-03 09:17:41 +00:00
else if (!fileExt)
result.message = "The file has no valid extension!";
2001-11-03 09:17:41 +00:00
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;
2001-11-03 09:17:41 +00:00
var saveTo = getProperty("goodiePath") + this._parent.alias + "/";
// any errors?
if (param.rawgoodie.writeToFile(saveTo,newGoodie.file)) {
2001-11-03 09:17:41 +00:00
// the goodie is on disk, so we add the goodie-object
newGoodie.creator = creator;
newGoodie.createtime = new Date();
if (this.add(newGoodie)) {
result.message = "The goodie " + newGoodie.alias + " was added successfully!";
result.error = false;
} else
result.message = "Ooops! Adding the goodie " + newGoodie.alias + " failed!";
} else
result.message = "Couldn't store the file on disk!";
2001-11-03 09:17:41 +00:00
}
}
}
return (result);
2001-11-03 09:17:41 +00:00
}
/**
* 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
* @return Boolean true in any case ...
2001-11-03 09:17:41 +00:00
*/
function changeAlias(currGoodie,newAlias) {
2001-11-03 09:17:41 +00:00
this.remove(currGoodie);
this.set(currGoodie.alias,null);
currGoodie.alias = newAlias.alias;
2001-11-03 09:17:41 +00:00
this.add(currGoodie);
return true;
2001-11-03 09:17:41 +00:00
}
/**
* delete a goodie
* @param Obj goodie-object to delete
* @return String Message indicating success or failure
2001-11-03 09:17:41 +00:00
*/
function deleteGoodie(currGoodie) {
// first we try to remove the goodie from disk
var f = new File(getProperty("goodiePath") + currGoodie.weblog.alias, currGoodie.file);
if (f.remove()) {
if (this.remove(currGoodie))
return ("The goodie was deleted successfully!");
2001-11-03 09:17:41 +00:00
else
return ("Ooops! Couldn't delete the goodie!");
2001-11-03 09:17:41 +00:00
} else
return ("Ooops! Couldn't remove the goodie from disk!");
2001-11-03 09:17:41 +00:00
}