Index: openacs-4/packages/ajax-filestorage-ui/ajax-filestorage-ui.info =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/ajax-filestorage-ui.info,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/ajax-filestorage-ui.info 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/ajax-filestorage-ui.info 8 Sep 2007 14:32:50 -0000 1.3 @@ -6,21 +6,24 @@ Ajax File Storage UIs f f - ajaxfs + ajaxfs2 - + Hamilton Chua 2006-06-01 Solutiongrove + 0 - + + + - \ No newline at end of file + Index: openacs-4/packages/ajax-filestorage-ui/catalog/ajax-filestorage-ui.en_US.ISO-8859-1.xml =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/catalog/ajax-filestorage-ui.en_US.ISO-8859-1.xml,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/catalog/ajax-filestorage-ui.en_US.ISO-8859-1.xml 8 Sep 2007 14:32:50 -0000 1.1 @@ -0,0 +1,47 @@ + + + + Alert + Browse + Cancel + Cancelled (This item will be removed shortly) + The root folder can not be deleted. + Your changes have been reverted + Close + Complete. + Confirm + Are you sure you want to delete + Copy the highlighted text to your clipboard. + Sorry, there was an error trying to create your new folder. + Create URL failed, please try again later. + Sorry, there was an error trying to delete this item. + Description + Duplicate Name + Please enter a different name. The name you entered is already being used. + Error + Sorry, an error occurred moving this item. A file with the same name may already exist in the target folder. + An error occurred + Sorry, we encountered an error rendering the tree panel + An error occurred. Your changes have been reverted + File List + File to upload + This folder contains + A folder name is required + for upload to + <b>URL</b> is not a valid url. + Please limit your name to 100 characters or less. + Multiple Files + Sorry, you do not have permission to rename this folder + OK + One moment. This may take a while depending on how large your upload is. + Permission Denied + Properties + Your session has expired. You need to login again. <br>You will be redirected to a login page shortly + This is a ZIP file containing multiple files. + Title + <b>Title</b> and <b>File to upload</b> are required. + Upload failed, please try again later. + Click <b>Browse</b> to select a file to upload to the selected folder. + Uploading ... + Zip File (Will be extracted after upload) + Index: openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.adp 8 Sep 2007 14:32:51 -0000 1.1 @@ -0,0 +1,77 @@ + + + + + + + + + + + + + \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/lib/ajaxfs-include.tcl 8 Sep 2007 14:32:51 -0000 1.1 @@ -0,0 +1,48 @@ +# ajax-filestorage-ui/lib/ajaxfs-include.tcl +# This include should be placed on a page +# where you wish to have an ajaxfs instance +# this include expects the following variables +# package_id : package_id of the file storage instance +# folder_id : the folder that will be opened on load, defaults to the root folder +# layoutdiv : the id of the div element where you want ajaxfs to be rendered +# theme : can be any of the following +# - default +# - aero +# - gray +# - vista + +set user_id [ad_conn user_id] + +if { [exists_and_not_null root_folder_id] } { + if { ![db_0or1row "get_folder_name" "select name as instance_name from fs_folders where folder_id = :root_folder_id"] } { + ad_return_complaint 1 "Root folder does not exist." + ad_script_abort + } + set package_id [ajaxfs::get_root_folder -folder_id $root_folder_id] +} + +if { [exists_and_not_null package_id] } { + append options "package_id:$package_id" + append options ",package_url:\"[apm_package_url_from_id $package_id]\"" + if { [exists_and_not_null root_folder_id] } { + append options ",rootfolder:$root_folder_id" + } + if { [exists_and_not_null folder_id] } { + append options ",initOpenFolder:$folder_id" + append options ",pathToFolder: new Array([ajaxfs::generate_path -folder_id $folder_id])" + } + if { [exists_and_not_null public] } { + append options ",ispublic:$public" + } + if { [exists_and_not_null layoutdiv] } { + append options ",layoutdiv:\"$layoutdiv\"" + } else { + set layoutdiv "fscontainer" + } + set max_file_size [parameter::get -package_id $package_id -parameter "MaximumFileSize"] + append options ",max_file_size:\"$max_file_size\"" + append options ",user_id:\"$user_id\"" +} else { + ad_return_complaint 1 "Package id is required." + ad_script_abort +} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/tcl/ajax-filestorage-ui-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/tcl/ajax-filestorage-ui-procs.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajax-filestorage-ui/tcl/ajax-filestorage-ui-procs.tcl 6 Nov 2006 13:15:56 -0000 1.1 +++ openacs-4/packages/ajax-filestorage-ui/tcl/ajax-filestorage-ui-procs.tcl 8 Sep 2007 14:32:51 -0000 1.2 @@ -1,16 +1,17 @@ ad_library { Library for Ajax File Storage UI - uses Ajax Helper package with the Yahoo User Interface Library. + uses Ajax Helper package with ExtJS and the Yahoo User Interface Library. http://developer.yahoo.net/yui/index.html + http://extjs.com/deploy/ext/docs/ @author Hamilton Chua (ham@solutiongrove.com) @creation-date 2006-02-24 } -namespace eval afs { } +namespace eval ajaxfs { } -ad_proc -private afs::get_package_id { +ad_proc -private ajaxfs::get_package_id { } { Return the package_id of the installed and mounted ajax file storage ui @@ -22,10 +23,10 @@ @error } { - return [apm_package_id_from_key "ajax-file-storage-ui"] + return [apm_package_id_from_key "ajax-filestorage-ui"] } -ad_proc -private afs::get_url { +ad_proc -private ajaxfs::get_url { } { Return the URL to the mounted ajax file storage ui instance @@ -37,10 +38,10 @@ @error } { - return [apm_package_url_from_id [afs::get_package_id]] + return [apm_package_url_from_id [ajaxfs::get_package_id]] } -ad_proc -private afs::root_folder_p { +ad_proc -private ajaxfs::root_folder_p { -folder_id:required } { Determine if the given folder id is a root folder @@ -61,7 +62,7 @@ } } -ad_proc -private afs::get_root_folder { +ad_proc -private ajaxfs::get_root_folder { -folder_id:required } { Check if the given folder is a root folder, if not then get the parent. Continue to get the parent until @@ -75,12 +76,54 @@ } { set root_found 0 while {$root_found == 0} { - set root_package_id [afs::root_folder_p -folder_id $folder_id] + set root_package_id [ajaxfs::root_folder_p -folder_id $folder_id] if { $root_package_id != "" } { set root_found 1 } else { set folder_id [db_string "getfolderparent" "select parent_id from cr_items where item_id=:folder_id"] } } return $root_package_id -} \ No newline at end of file +} + +ad_proc -private ajaxfs::generate_path { + -folder_id:required +} { + + Generates a comma separated list of folder_id's that start from the root folder to the give folder_id + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-07-07 + @return + + @error +} { + set id_list [list] + lappend id_list $folder_id + set root_found 0 + while {$root_found == 0} { + set root_package_id [ajaxfs::root_folder_p -folder_id $folder_id] + if { $root_package_id != "" } { + set root_found 1 + } else { + set folder_id [db_string "getfolderparent" "select parent_id from cr_items where item_id=:folder_id"] + lappend id_list $folder_id + } + } + + proc lreverse l { + set result {} + set i [llength $l] + incr i -1 + while {$i >= 0} { + lappend result [lindex $l $i] + incr i -1 + } + return $result + } + + # reverse order of list + # join with ',' and return + set path [join [lreverse $id_list] ","] + return $path +} Index: openacs-4/packages/ajax-filestorage-ui/www/index.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/Attic/index.adp,v diff -u -r1.3 -r1.4 --- openacs-4/packages/ajax-filestorage-ui/www/index.adp 25 Dec 2006 16:23:26 -0000 1.3 +++ openacs-4/packages/ajax-filestorage-ui/www/index.adp 8 Sep 2007 14:32:51 -0000 1.4 @@ -1,49 +1,85 @@ -@doc_type;noquote@ + @page_title@ - - - - - - - + + - + + + + + - - + -
- -



No folders found.
-
-
-
Click a file to get more information
-
-
-
This item does not have any revisions
-
-
-
- - - - - - - -
FilenameSizeTypeLast Modified
-
-

Click on an item in the file tree to view its contents here.
-
-
-
-@js_script;noquote@ + + +
\ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/index.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/Attic/index.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/index.tcl 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/index.tcl 8 Sep 2007 14:32:54 -0000 1.3 @@ -1,65 +1,48 @@ -# ajax-filestorage-ui/www/index.tcl - ad_page_contract { - Ajax Based File Manager using OpenACS File Storage and Yahoo's Tree View Control. - Optionally specify a package_id of the file storage instance you wish to manage - or optionally specify a folder_id in the query string to tell which folder to open + Sample page that loads ajax file storage + @author Hamilton Chua (ham@solutiongrove.com) - @author Hamilton Chua (ham@solutiongrove.com) - @creation-date 2006-02-04 } { - {package_ids:integer,multiple,optional } + {package_id:integer,optional} + {root_folder_id:integer,optional} {folder_id:integer,optional } } -# declare some variables -set page_title "Ajax File Storage" -set doc_type { } +set user_id [ad_conn user_id] +set page_title "Ajax File Storage UI" +set options "" -# where is afs mounted -set afs_url [afs::get_url] - -# who is viewing, used to check permissions -set viewing_user_id [auth::require_login] - -# holds counter for number of folders -set count_folders 0 - -# variable name for the tree view control -set treevarname "tree" - -# refine query -set exclude_sql "" -# did we get a package_id from querystring -if { [exists_and_not_null package_ids] } { - set package_ids_list [join $package_ids ","] - set exclude_sql "and package_id in ($package_ids_list)" +if { [exists_and_not_null root_folder_id] } { + if { ![db_0or1row "get_folder_name" "select name as instance_name from fs_folders where folder_id = :root_folder_id"] } { + ad_return_complaint 1 "Root folder does not exist." + ad_script_abort + } + set package_id [ajaxfs::get_root_folder -folder_id $root_folder_id] } -# create the nodes for our tree -set nodes [list] -db_foreach "get_fs_instances" "" { - - # verify if the folder has contents - if { [db_string "countcontent" ""] > 0 } { - # loadDataForNode is a javascript function found in ajaxfs.js - # it is responsible for loading the child nodes when the current node is opened - set dyn_load_script "loadDataForNode" - } else { - set dyn_load_script "" - } - - # create the node - lappend nodes [list "$root_folder" "$instance_name" "$treevarname" "javascript:showFolderContents('${root_folder}',$treevarname,'name')" "" "${dyn_load_script}" "1"] - - incr count_folders - -} - -set js_script [ah::yui::create_tree -element "folders" \ - -nodes $nodes \ - -varname $treevarname \ - -css "/resources/ajax-filestorage-ui/tree.css" ] - -set js_script [ah::enclose_in_script -script $js_script] \ No newline at end of file +if { [exists_and_not_null package_id] } { + append options "package_id:$package_id" + append options ",package_url:\"[apm_package_url_from_id $package_id]\"" + if { [exists_and_not_null root_folder_id] } { + append options ",rootfolder:$root_folder_id" + } + if { [exists_and_not_null folder_id] } { + append options ",initOpenFolder:$folder_id" + append options ",pathToFolder: new Array([ajaxfs::generate_path -folder_id $folder_id])" + } + if { [exists_and_not_null public] } { + append options ",public:$public" + } + if { [exists_and_not_null layoutdiv] } { + append options ",layoutdiv:\"$layoutdiv\"" + } else { + set layoutdiv "fscontainer" + } + set max_file_size [parameter::get -package_id $package_id -parameter "MaximumFileSize"] + append options ",max_file_size:\"$max_file_size\"" + append options ",user_id:\"$user_id\"" +} else { + ad_return_complaint 1 "Package id is required." + ad_script_abort +} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/doc/index.html =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/doc/index.html,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/doc/index.html 8 Sep 2007 14:32:55 -0000 1.1 @@ -0,0 +1,43 @@ + + + +Ajax File Storage User Interface + + + + +

Ajax File Storage User Interface

+

Hamilton G. Chua (ham@solutiongrove.com)
+ September 2007
+ v0.8d

+

What's New :

+

v0.8d

+ +

Set Up

+

Install ajax-filestorage-ui thru acs-admin/install.

+

Before you can use ajaxfs-ui with your file storage instance, you need to make a few modifications to file-storage/www/index.adp. The code for index.adp is shown below and the changes that you must add are in red .

+

+<master>
<property name="title">@folder_name@</property>
<property name="header">@folder_name@</property>
<property name="context">@context;noquote@</property>
<property name="displayed_object_id">@folder_id;noquote@</property>
+<include src="/packages/ajax-filestorage-ui/lib/ajaxfs-include" package_id="@package_id@" folder_id="@folder_id@" layoutdiv="fscontainer"> + +<div id="fscontainer"> +<table>
<tr>
<td>
<if @up_url@ not nil>
<a href="@up_url@" class="button">#file-storage.index_page_navigate_up_folder#</a>
</if>
</td>
<td>
<if @project_url@ not nil>
<a href="@project_url@">#file-storage.back_to_project#: @project_name@</a>
</if>
</td>
</tr>
</table>
<include src="folder-chunk" folder_id="@folder_id@"
n_past_days="@n_past_days@" allow_bulk_actions="1" return_url="@return_url@">
</div> + +<div style="clear:both"></div> +<p>@notification_chunk;noquote@</p> +
+ + Index: openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs-min.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs-min.js,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs-min.js 8 Sep 2007 14:32:55 -0000 1.1 @@ -0,0 +1,968 @@ +function readCookie(_1){ +var ca=document.cookie.split(";"); +var _3=_1+"="; +for(var i=0;i0){ +var key=_d[i].substring(0,_f); +var val=_d[i].substring(_f+1); +if(key==q){ +return val; +} +} +} +return null; +} +function checkFlashVersion(){ +var x; +var _13; +if(navigator.plugins&&navigator.mimeTypes.length){ +x=navigator.plugins["Shockwave Flash"]; +if(x&&x.description){ +x=x.description; +} +}else{ +if(Ext.isIE){ +try{ +x=new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); +x=x.GetVariable("$version"); +} +catch(e){ +} +} +} +pluginVersion=(typeof (x)=="string")?parseInt(x.match(/\d+/)[0]):0; +return pluginVersion; +} +function isURL(_14){ +if(_14.indexOf(" ")!=-1){ +return false; +}else{ +if(_14.indexOf("http://")==-1){ +return false; +}else{ +if(_14=="http://"){ +return false; +}else{ +if(_14.indexOf("http://")>0){ +return false; +} +} +} +} +_14=_14.substring(7,_14.length); +if(_14.indexOf(".")==-1){ +return false; +}else{ +if(_14.indexOf(".")==0){ +return false; +}else{ +if(_14.charAt(_14.length-1)=="."){ +return false; +} +} +} +if(_14.indexOf("/")!=-1){ +_14=_14.substring(0,_14.indexOf("/")); +if(_14.charAt(_14.length-1)=="."){ +return false; +} +} +if(_14.indexOf(":")!=-1){ +if(_14.indexOf(":")==(_14.length-1)){ +return false; +}else{ +if(_14.charAt(_14.indexOf(":")+1)=="."){ +return false; +} +} +_14=_14.substring(0,_14.indexOf(":")); +if(_14.charAt(_14.length-1)=="."){ +return false; +} +} +return true; +} +function FileProgress(_15,_16){ +this.file_progress_id=_15.id; +this.opacity=100; +this.height=0; +this.fileProgressWrapper=document.getElementById(this.file_progress_id); +if(!this.fileProgressWrapper){ +this.fileProgressWrapper=document.createElement("div"); +this.fileProgressWrapper.className="progressWrapper"; +this.fileProgressWrapper.id=this.file_progress_id; +this.fileProgressElement=document.createElement("div"); +this.fileProgressElement.className="progressContainer"; +var _17=document.createElement("a"); +_17.className="progressCancel"; +_17.href="#"; +_17.style.visibility="hidden"; +_17.appendChild(document.createTextNode(" ")); +var _18=document.createElement("div"); +_18.className="progressName"; +_18.appendChild(document.createTextNode(_15.name)); +var _19=document.createElement("div"); +_19.className="progressBarInProgress"; +var _1a=document.createElement("div"); +_1a.className="progressBarStatus"; +_1a.innerHTML=" "; +this.fileProgressElement.appendChild(_17); +this.fileProgressElement.appendChild(_18); +this.fileProgressElement.appendChild(_1a); +this.fileProgressElement.appendChild(_19); +this.fileProgressWrapper.appendChild(this.fileProgressElement); +document.getElementById(_16).appendChild(this.fileProgressWrapper); +}else{ +this.fileProgressElement=this.fileProgressWrapper.firstChild; +} +this.height=this.fileProgressWrapper.offsetHeight; +} +FileProgress.prototype.SetProgress=function(_1b){ +this.fileProgressElement.className="progressContainer green"; +this.fileProgressElement.childNodes[3].className="progressBarInProgress"; +this.fileProgressElement.childNodes[3].style.width=_1b+"%"; +}; +FileProgress.prototype.SetComplete=function(){ +this.fileProgressElement.className="progressContainer blue"; +this.fileProgressElement.childNodes[3].className="progressBarComplete"; +this.fileProgressElement.childNodes[3].style.width=""; +var _1c=this; +setTimeout(function(){ +_1c.Disappear(); +},10000); +}; +FileProgress.prototype.SetError=function(){ +this.fileProgressElement.className="progressContainer red"; +this.fileProgressElement.childNodes[3].className="progressBarError"; +this.fileProgressElement.childNodes[3].style.width=""; +var _1d=this; +setTimeout(function(){ +_1d.Disappear(); +},5000); +}; +FileProgress.prototype.SetCancelled=function(){ +this.fileProgressElement.className="progressContainer"; +this.fileProgressElement.childNodes[3].className="progressBarError"; +this.fileProgressElement.childNodes[3].style.width=""; +var _1e=this; +setTimeout(function(){ +_1e.Disappear(); +},2000); +}; +FileProgress.prototype.SetStatus=function(_1f){ +this.fileProgressElement.childNodes[2].innerHTML=_1f; +}; +FileProgress.prototype.ToggleCancel=function(_20,_21){ +this.fileProgressElement.childNodes[0].style.visibility=_20?"visible":"hidden"; +if(_21){ +var _22=this.file_progress_id; +this.fileProgressElement.childNodes[0].onclick=function(){ +_21.cancelUpload(_22); +return false; +}; +} +}; +FileProgress.prototype.Disappear=function(){ +var _23=15; +var _24=4; +var _25=30; +if(this.opacity>0){ +this.opacity-=_23; +if(this.opacity<0){ +this.opacity=0; +} +if(this.fileProgressWrapper.filters){ +try{ +this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity=this.opacity; +} +catch(e){ +this.fileProgressWrapper.style.filter="progid:DXImageTransform.Microsoft.Alpha(opacity="+this.opacity+")"; +} +}else{ +this.fileProgressWrapper.style.opacity=this.opacity/100; +} +} +if(this.height>0){ +this.height-=_24; +if(this.height<0){ +this.height=0; +} +this.fileProgressWrapper.style.height=this.height+"px"; +} +if(this.height>0||this.opacity>0){ +var _26=this; +setTimeout(function(){ +_26.Disappear(); +},_25); +}else{ +this.fileProgressWrapper.style.display="none"; +} +}; +function uploadStart(_27,_28){ +var _29=acs_lang_text.for_upload_to||"for upload to"; +var _2a=acs_lang_text.zip_extracted||"Zip File (Will be extracted after upload)"; +try{ +var _2b=_28.currentfolder; +var _2c=_28.treepanel.getNodeById(_2b).text; +var _2d=new FileProgress(_27,this.getSetting("progress_target")); +_2d.SetStatus(_29+""+_2c+"
"+_2a); +_2d.ToggleCancel(true,this); +this.addFileParam(_27.id,"folder_id",_2b); +_28.upldDialog.buttons[0].enable(); +} +catch(ex){ +this.debugMessage(ex); +} +} +function uploadProgress(_2e,_2f){ +try{ +var _30=Math.ceil((_2f/_2e.size)*100); +var _31=new FileProgress(_2e,this.getSetting("progress_target")); +_31.SetProgress(_30); +_31.SetStatus(acs_lang_text.uploading||"Uploading..."); +} +catch(ex){ +this.debugMessage(ex); +} +} +function uploadFileComplete(_32){ +try{ +var _33=new FileProgress(_32,this.getSetting("progress_target")); +_33.SetComplete(); +_33.SetStatus(acs_lang_text.complete||"Complete."); +_33.ToggleCancel(false); +} +catch(ex){ +this.debugMessage(ex); +} +} +function uploadComplete(_34){ +try{ +var _35=new FileProgress(_34,this.getSetting("progress_target")); +_35.SetComplete(); +_35.SetStatus(acs_lang_text.complete||"Complete."); +_35.ToggleCancel(false); +} +catch(ex){ +this.debugMessage(ex); +} +} +function uploadQueueComplete(_36,_37){ +_37.upldDialog.buttons[0].disable(); +var _38=_37.treepanel.getNodeById(_37.currentfolder); +_38.fireEvent("click",_38); +} +function uploadError(_39,_3a,_3b){ +try{ +if(_39==SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED){ +Ext.Msg.alert(acs_lang_text.alert||"Alert","You have attempted to queue too many files.\n"+(_3b==0?"You have reached the upload limit.":"You may select "+(_3b>1?"up to "+_3b+" files.":"one file."))); +return; +} +var _3c=new FileProgress(_3a,this.getSetting("progress_target")); +_3c.SetError(); +_3c.ToggleCancel(false); +switch(_39){ +case SWFUpload.ERROR_CODE_HTTP_ERROR: +_3c.SetStatus("Upload Error"); +this.debugMessage("Error Code: HTTP Error, File name: "+file.name+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET: +_3c.SetStatus("Configuration Error"); +this.debugMessage("Error Code: No backend file, File name: "+file.name+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_UPLOAD_FAILED: +_3c.SetStatus("Upload Failed."); +this.debugMessage("Error Code: Upload Failed, File name: "+file.name+", File size: "+file.size+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_IO_ERROR: +_3c.SetStatus("Server (IO) Error"); +this.debugMessage("Error Code: IO Error, File name: "+file.name+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_SECURITY_ERROR: +_3c.SetStatus("Security Error"); +this.debugMessage("Error Code: Security Error, File name: "+file.name+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT: +_3c.SetStatus("File is too big."); +this.debugMessage("Error Code: File too big, File name: "+file.name+", File size: "+file.size+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE: +_3c.SetStatus("Cannot upload Zero Byte files."); +this.debugMessage("Error Code: Zero byte file, File name: "+file.name+", File size: "+file.size+", Message: "+_3b); +break; +case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED: +_3c.SetStatus("Upload limit exceeded."); +this.debugMessage("Error Code: Upload Limit Exceeded, File name: "+file.name+", File size: "+file.size+", Message: "+_3b); +break; +default: +_3c.SetStatus("Unhandled Error"); +this.debugMessage("Error Code: "+_39+", File name: "+file.name+", File size: "+file.size+", Message: "+_3b); +break; +} +} +catch(ex){ +this.debugMessage(ex); +} +} +function uploadCancel(_3d){ +try{ +var _3e=new FileProgress(_3d,this.getSetting("progress_target")); +_3e.SetCancelled(); +_3e.SetStatus(acs_lang_text.uploadcancel||"Cancelled (This item will be removed shortly)"); +_3e.ToggleCancel(false); +} +catch(ex){ +this.debugMessage(ex); +} +} +function ajaxfs(_3f){ +this.xmlhttpurl="/ajaxfs2/xmlhttp/"; +this.config=null; +this.layout=null; +this.treepanel=null; +this.te=null; +this.rootfolder=null; +this.filegrid=null; +this.toolbar=null; +this.currentfolder=null; +this.asyncCon=new Ext.data.Connection(); +this.msgbox=Ext.MessageBox; +this.upldDialog=null; +this.createurlDialog=null; +this.permsDialog=null; +this.revisionsDialog=null; +this.contextmenu=null; +this.swfu=null; +this.isSessionExpired=function(){ +if(readCookie("ad_user_login")==null){ +Ext.get(document.body).mask(acs_lang_text.sessionexpired||"Your session has expired. You need to login again.
You will be redirected to a login page shortly"); +var _40="package_id="+this.config.package_id; +if(this.currentfolder!=null){ +_40=_40+"&folder_id="+this.currentfolder; +} +window.location="/register/?return_url="+window.location; +return 1; +} +return 0; +}; +this.isPermitted=function(_41,_42){ +var _43=function(_44,_45,_46){ +if(_45){ +return _46.responseText; +}else{ +return 0; +} +}; +this.asyncCon.request({url:this.xmlhttpurl+"checkperms",params:"object_id="+_41+"&perm="+_42,method:"POST",callback:_43,scope:this}); +}; +this.createGridPanel=function(_47,_48,_49){ +gridPanel=new Ext.GridPanel(_47,_49); +this.layout.add(_48,gridPanel); +}; +this.linkCopy=function(){ +var _4a=this.filegrid.getSelectionModel().getSelected(); +var _4b=_4a.get("type"); +if(_4b==="folder"){ +var _4c=window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"?package_id="+this.config.package_id+"&folder_id="+_4a.get("id"); +}else{ +if(_4b==="url"){ +var _4c=_4a.get("url"); +}else{ +var _4c=window.location.protocol+"//"+window.location.hostname+_4a.get("url"); +} +} +if(Ext.isIE){ +window.clipboardData.setData("text",_4c); +}else{ +var _4d=Ext.Msg.show({title:acs_lang_text.linkaddress||"Copy Link Address",prompt:true,msg:acs_lang_text.copyhighlighted||"Copy the highlighted text to your clipboard.",value:_4c,buttons:Ext.Msg.OK}); +var _4e=YAHOO.util.Dom.getElementsByClassName("ext-mb-input","input","x-msg-box"); +_4e[0].select(); +} +}; +this.fileRename=function(){ +var _4f=this.filegrid.getSelectionModel().getSelected(); +var _50=_4f.get("url"); +var _51=_4f.get("type"); +var _52=_4f.get("id"); +var _53=_4f.get("filename"); +var _54=function(btn,_56){ +if(btn=="ok"){ +if(_56!=""){ +if(_56.length>100){ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.limitto100||"Please limit your name to 100 characters or less."); +return false; +}else{ +var _57=function(_58,_59,_5a){ +var _5b=acs_lang_text.an_error_occurred||"An error occurred"; +var _5c=acs_lang_text.reverted||"Your changes have been reverted"; +if(_59){ +if(_5a.responseText!=1){ +Ext.Msg.alert(acs_lang_text.error||"Error",_5b+":

"+_5a.responseText+"

"+_5c); +}else{ +if(_51!="folder"&&_53===" "){ +_53=_4f.get("title"); +} +if(_51=="folder"){ +this.treepanel.getNodeById(_52).setText(_56); +} +_4f.set("title",_56); +_4f.set("title_and_name",""+_56+"
"+_53+""); +_4f.commit(); +} +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",err_msg_text+":

"+_5a.responseText+"

"+_5c); +} +}; +this.asyncCon.request({url:this.xmlhttpurl+"editname",params:"newname="+_56+"&object_id="+_52+"&type="+_51+"&url="+_50,method:"POST",callback:_57,scope:this}); +} +}else{ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.enter_new_name||"Please enter a new name."); +return false; +} +} +}; +Ext.Msg.show({title:acs_lang_text.rename||"Rename",prompt:true,msg:acs_lang_text.enter_new_name||"Please enter a new name for ... ",value:_4f.get("title"),buttons:Ext.Msg.OKCANCEL,fn:_54.createDelegate(this)}); +var _5d=YAHOO.util.Dom.getElementsByClassName("ext-mb-input","input","x-msg-box"); +_5d[0].select(); +}; +this.permsRedirect=function(){ +var _5e=this.filegrid.getSelectionModel().getSelected(); +var _5f=_5e.get("id"); +var _60=window.open(window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"permissions?object_id="+_5f+"&return_url="+window.location.pathname+"?package_id="+this.config.package_id+"&folder_id="+this.currentfolder); +_60.focus(); +}; +this.propertiesRedirect=function(){ +var _61=this.filegrid.getSelectionModel().getSelected(); +var _62=_61.get("id"); +var _63=window.open(window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"file?file_id="+_62); +_63.focus(); +}; +this.showContext=function(_64,i,e){ +e.stopEvent(); +if(this.contextmenu==null){ +this.contextmenu=new Ext.menu.Menu({id:"rightclickmenu",items:[new Ext.menu.Item({text:acs_lang_text.deletefs||"Delete",icon:"/resources/ajax-filestorage-ui/icons/delete.png",handler:this.confirmDel.createDelegate(this)}),new Ext.menu.Item({text:acs_lang_text.rename||"Rename",icon:"/resources/ajax-filestorage-ui/icons/page_edit.png",handler:this.fileRename.createDelegate(this)}),new Ext.menu.Item({text:acs_lang_text.linkaddress||"Copy Link Address",icon:"/resources/ajax-filestorage-ui/icons/page_copy.png",handler:this.linkCopy.createDelegate(this)}),new Ext.menu.Item({text:acs_lang_text.permissions||"Permissions",icon:"/resources/ajax-filestorage-ui/icons/group_key.png",handler:this.permsRedirect.createDelegate(this)}),new Ext.menu.Item({text:acs_lang_text.properties||"Properties",icon:"/resources/ajax-filestorage-ui/icons/page_edit.png",handler:this.propertiesRedirect.createDelegate(this)})]}); +} +if(_64.getSelectionModel().getCount()>1){ +this.contextmenu.items.items[1].disable(); +this.contextmenu.items.items[2].disable(); +this.contextmenu.items.items[3].disable(); +this.contextmenu.items.items[4].disable(); +}else{ +this.contextmenu.items.items[1].enable(); +this.contextmenu.items.items[2].enable(); +this.contextmenu.items.items[3].enable(); +var _67=this.filegrid.getSelectionModel().getSelected(); +var _68=_67.get("type"); +if(_68=="folder"||_68=="url"){ +this.contextmenu.items.items[4].disable(); +}else{ +this.contextmenu.items.items[4].enable(); +} +} +var _69=e.getXY(); +this.contextmenu.rowid=i; +this.contextmenu.showAt([_69[0],_69[1]]); +}; +this.uploadFile=function(e){ +if(document.getElementById("upload_file").value!=""&&document.getElementById("filetitle").value!=""){ +var _6b={success:function(){ +},upload:function(){ +this.treepanel.getSelectionModel().getSelectedNode().loaded=false; +this.treepanel.getSelectionModel().getSelectedNode().fireEvent("click",this.treepanel.getSelectionModel().getSelectedNode()); +this.upldDialog.getEl().unmask(); +this.upldDialog.hide(); +},failure:function(){ +Ext.Msg.alert(acs_lang_text.error||"Error",acs_lang_text.upload_failed||"Upload failed, please try again later."); +},scope:this}; +var _6c=acs_lang_text.loading||"One moment. This may take a while depending on how large your upload is."; +this.upldDialog.getEl().mask(" "+_6c); +YAHOO.util.Connect.setForm("newfileform",true,true); +var _6d=YAHOO.util.Connect.asyncRequest("POST",this.xmlhttpurl+"file-add",_6b); +}else{ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.file_required||"Title and File to upload are required."); +} +}; +this.createUrl=function(e){ +if(document.getElementById("fsurl").value!=""&&document.getElementById("fstitle").value!=""){ +if(isURL(document.getElementById("fsurl").value)){ +var _6f={success:function(){ +this.treepanel.getSelectionModel().getSelectedNode().loaded=false; +this.treepanel.getSelectionModel().getSelectedNode().fireEvent("click",this.treepanel.getSelectionModel().getSelectedNode()); +this.createurlDialog.getEl().unmask(); +this.createurlDialog.hide(); +},failure:function(){ +this.createurlDialog.getEl().unmask(); +Ext.Msg.alert(acs_lang_text.error||"Error",acs_lang_text.createurl_failed||"Create URL failed, please try again later."); +},scope:this}; +this.createurlDialog.getEl().mask(" One moment."); +YAHOO.util.Connect.setForm("simple-add"); +var _70=YAHOO.util.Connect.asyncRequest("POST",this.xmlhttpurl+"url-add",_6f); +}else{ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.invalid_url||"URL is not a valid url."); +} +}else{ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.invalid_url||"Title and URL are required."); +} +}; +this.showCreateUrldialog=function(){ +if(!this.createurlDialog.buttons){ +this.createurlDialog.addButton({text:acs_lang_text.ok||"Ok",icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"},this.createUrl,this); +this.createurlDialog.addButton({text:acs_lang_text.cancel||"Cancel",icon:"/resources/ajax-filestorage-ui/icons/cancel.png",cls:"x-btn-text-icon"},this.createurlDialog.hide,this.createurlDialog); +} +this.createurlDialog.setTitle(acs_lang_text.createurl||"Create URL"); +this.createurlDialog.body.update("

Title


URL


Description :

"); +this.createurlDialog.body.setStyle("font","normal 12px tahoma, arial, helvetica, sans-serif"); +this.createurlDialog.body.setStyle("background-color","#ffffff"); +this.createurlDialog.body.setStyle("border","1px solid #e2e2e2"); +this.createurlDialog.body.setStyle("padding","3px"); +this.createurlDialog.show(); +}; +this.showUplddialog=function(){ +this.upldDialog.setTitle(acs_lang_text.uploadfile||"Upload Files"); +if(checkFlashVersion()<8){ +var _71=acs_lang_text.file_to_upload||"File to upload"; +var _72=acs_lang_text.file_title||"Title"; +var _73=acs_lang_text.file_description||"Description"; +var _74=acs_lang_text.multiple_files||"Multiple Files"; +var _75=acs_lang_text.multiple_files_msg||"This is a ZIPfile containing multiple files."; +this.upldDialog.body.update("

"+_71+"


"+_72+"


"+_73+" :

"+_74+" :

"+_75+"

"); +if(!this.upldDialog.buttons){ +this.upldDialog.addButton({text:acs_lang_text.upload||"Upload",icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"},this.uploadFile,this); +this.upldDialog.addButton({text:acs_lang_text.cancel||"Cancel",icon:"/resources/ajax-filestorage-ui/icons/cancel.png",cls:"x-btn-text-icon"},this.upldDialog.hide,this.upldDialog); +} +}else{ +if(this.swfu==null){ +var _76=acs_lang_text.upload_intro||"Click Browse to select a file to upload to the selected folder."; +this.upldDialog.body.update("
"+_76+"
"); +var _77=String(this.config.package_id); +var _78=String(this.config.user_id); +var _79=String(this.currentfolder); +var _7a=String(this.config.max_file_size)||5000000; +this.swfu=new SWFUpload({debug:false,upload_target_url:"/ajaxfs2/xmlhttp/file-add-flash",upload_params:{user_id:_78,package_id:_77},file_types:"*.*",file_size_limit:_7a,file_queue_limit:3,begin_upload_on_queue:false,file_progress_handler:uploadProgress,file_cancelled_handler:uploadCancel,file_complete_handler:uploadComplete,queue_complete_handler:uploadQueueComplete,error_handler:uploadError,flash_url:"/resources/ajax-filestorage-ui/swfupload/swfupload.swf"}); +this.swfu.fileQueued=uploadStart.createDelegate(this.swfu,[this],true); +this.swfu.fileProgress=uploadProgress.createDelegate(this.swfu,[this],true); +this.swfu.fileComplete=uploadComplete.createDelegate(this.swfu,[this],true); +this.swfu.fileCancelled=uploadCancel.createDelegate(this.swfu,[this],true); +this.swfu.queueComplete=uploadQueueComplete.createDelegate(this.swfu,[this],true); +this.swfu.addSetting("progress_target","fsuploadprogress"); +this.upldDialog.addButton({text:acs_lang_text.upload||"Upload",disabled:true,icon:"/resources/ajax-filestorage-ui/icons/arrow_up.png",cls:"x-btn-text-icon"},this.swfu.startUpload.createDelegate(this.swfu,[null,this],false),this); +this.upldDialog.addButton({text:acs_lang_text.browse||"Browse",icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"},this.swfu.browse,this.swfu); +this.upldDialog.addButton({text:acs_lang_text.close||"Close",icon:"/resources/ajax-filestorage-ui/icons/cross.png",cls:"x-btn-text-icon"},this.upldDialog.hide,this.upldDialog); +} +} +this.upldDialog.body.setStyle("font","normal 12px tahoma, arial, helvetica, sans-serif"); +this.upldDialog.body.setStyle("background-color","#ffffff"); +this.upldDialog.body.setStyle("border","1px solid #e2e2e2"); +this.upldDialog.body.setStyle("padding","3px"); +this.upldDialog.show(); +}; +this.confirmDel=function(){ +var _7b=acs_lang_text.confirm_delete||"Are you sure you want to delete"; +var _7c=acs_lang_text.foldercontains||"This folder contains"; +var _7d=this.filegrid.getSelectionModel().getSelections(); +if(_7d.length>0){ +if(_7d.length==1){ +var _7e=_7d[0].get("title"); +if(_7d[0].get("type")==="folder"){ +var msg=_7c+" "+_7d[0].get("size")+".
"; +}else{ +var msg=""; +} +var msg=msg+_7b+" "+_7e+" ?"; +}else{ +var msg=_7b+":

"; +for(var x=0;x<_7d.length;x++){ +msg=msg+""+_7d[x].get("title")+" "; +if(_7d[x].get("type")==="folder"){ +msg=msg+"("+_7d[x].get("size")+")"; +} +msg=msg+"
"; +} +} +this.msgbox.confirm(acs_lang_text.confirm||"Confirm",msg,this.delFsitems,this); +}else{ +var _81=this.treepanel.getSelectionModel().getSelectedNode(); +var _82=this.treepanel.getRootNode(); +if(_81.attributes["id"]==_82.attributes["id"]){ +Ext.Msg.alert(acs_lang_text.alert||"Alert",acs_lang_text.cant_del_root||"The root folder can not be deleted."); +}else{ +this.msgbox.confirm(acs_lang_text.confirm||"Confirm",_7b+" "+_81.attributes["text"]+"?",this.delFolder,this); +} +} +}; +this.delFsitems=function(_83){ +var _84=this.filegrid.getSelectionModel().getSelections(); +var _85=[]; +for(var x=0;x<_84.length;x++){ +_85[x]=_84[x].get("id"); +} +var _87=function(_88,_89,_8a){ +var _8b=acs_lang_text.delete_error||"Sorry, there was an error trying to delete this item."; +if(_89&&_8a.responseText==1){ +for(var x=0;x<_84.length;x++){ +this.filegrid.getDataSource().remove(_84[x]); +var _8d=_84[x].get("id"); +var _8e=this.treepanel.getNodeById(_8d); +if(_8e){ +_8e.parentNode.fireEvent("click",_8e.parentNode); +_8e.parentNode.removeChild(_8e); +} +} +this.filegrid.getSelectionModel().clearSelections(); +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",_8b+"

"+_8a.responseText+""); +} +this.filegrid.container.unmask(); +}; +var _8f="object_id="+_85; +var url=this.xmlhttpurl+"delete"; +if(_83==="yes"){ +this.filegrid.container.mask("Deleting"); +this.asyncCon.request({url:url,params:_8f,method:"POST",callback:_87,scope:this}); +} +}; +this.delFolder=function(_91){ +var _92=this.treepanel.getSelectionModel().getSelectedNode(); +var _93=_92.parentNode; +var id=_92.attributes["id"]; +var _95=function(_96,_97,_98){ +var _99=acs_lang_text.delete_error||"Sorry, there was an error trying to delete this item."; +if(_97){ +if(_98.responseText!="1"){ +Ext.Msg.alert(acs_lang_text.error||"Error",_99+"

"+_98.responseText+""); +}else{ +_93.fireEvent("click",_93); +_93.removeChild(_92); +} +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",_99+"

"+_98.responseText+""); +} +}; +if(_91==="yes"){ +this.asyncCon.request({url:this.xmlhttpurl+"delete",params:"object_id="+id,method:"POST",callback:_95,scope:this}); +} +}; +this.newFolder=function(){ +var te=this.te; +var _9b=this.treepanel; +var _9c=_9b.getSelectionModel().getSelectedNode(); +_9c.expand(); +var _9d=function(_9e,_9f,_a0){ +var _a1=acs_lang_text.new_folder_error||"Sorry, there was an error trying to create your new folder."; +if(_9f){ +if(!isNaN(parseInt(_a0.responseText))){ +if(parseInt(_a0.responseText)!=0){ +var _a2=_9c.appendChild(new Ext.tree.TreeNode({text:acs_lang_text.new_folder_label||"New Folder",id:_a0.responseText,iconCls:"folder",singleClickExpand:true,attributes:{write_p:"t"}})); +_9b.getSelectionModel().select(_a2); +_a2.loaded=true; +_a2.fireEvent("click",_a2); +setTimeout(function(){ +te.editNode=_a2; +te.startEdit(_a2.ui.textNode); +},10); +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",_a1+"

"+_a0.responseText+""); +} +} +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",_a1+"

"+_a0.responseText+""); +} +}; +this.asyncCon.request({url:this.xmlhttpurl+"newblankfolder",params:"folder_id="+_9c.attributes["id"],method:"POST",callback:_9d,scope:this}); +}; +this.itemDblClick=function(_a3,i,e){ +var dm=_a3.getDataSource(); +var _a7=dm.getAt(i); +if(_a7.get("type")=="folder"){ +var _a8=this.treepanel.getNodeById(_a7.get("id")); +if(!_a8.parentNode.isExpanded()){ +_a8.parentNode.expand(); +} +_a8.fireEvent("click",_a8); +_a8.expand(); +}else{ +window.open(_a7.get("url")); +window.focus(); +} +}; +this.loadFoldercontents=function(_a9,e){ +if(this.currentfolder!=null){ +this.treepanel.getNodeById(this.currentfolder).getUI().removeClass("x-tree-grayselected"); +} +this.currentfolder=_a9.id; +if(this.filegrid==null){ +var _ab=[{header:"",width:50,sortable:true,dataIndex:"icon"},{header:acs_lang_text.filename||"Filename",id:"filename",width:200,sortable:true,dataIndex:"title_and_name"},{header:acs_lang_text.size||"Size",sortable:true,dataIndex:"size"},{header:acs_lang_text.lastmodified||"Last Modified",sortable:true,dataIndex:"lastmodified"}]; +var _ac=new Ext.grid.ColumnModel(_ab); +_ac.defaultSortable=true; +var _ad=new Ext.data.JsonReader({totalProperty:"total",root:"foldercontents",id:"id"},[{name:"id",type:"int"},{name:"icon"},{name:"title"},{name:"filename"},{name:"type"},{name:"url"},{name:"write_p"},{name:"title_and_name"},{name:"size"},{name:"lastmodified"}]); +var _ae=new Ext.data.HttpProxy({url:this.xmlhttpurl+"foldercontents"}); +var _af=new Ext.data.Store({proxy:_ae,reader:_ad,remoteSort:true}); +this.filegrid=new Ext.grid.Grid("files",{ds:_af,cm:_ac,autoHeight:false,autoWidth:true,autoSizeColumns:false,trackMouseOver:true,autoExpandColumn:"filename",enableColumnMove:false,enableColLock:false,enableColumnHide:false,loadMask:true,monitorWindowResize:true,enableDragDrop:true,ddGroup:"fileDD"}); +this.filegrid.on("rowclick",function(){ +this.treepanel.getSelectionModel().getSelectedNode().getUI().removeClass("x-tree-selected"); +this.treepanel.getSelectionModel().getSelectedNode().getUI().addClass("x-tree-grayselected"); +},this,true); +this.filegrid.on("rowdblclick",this.itemDblClick,this,true); +this.filegrid.on("rowcontextmenu",this.showContext,this,true); +var _b0=this.filegrid; +var _b1=this; +var _b2=new Ext.dd.DropTarget(_b0.container,{ddGroup:"fileDD",copy:false,notifyDrop:function(dd,e,_b5){ +var ds=_b0.getDataSource(); +var sm=_b0.getSelectionModel(); +var _b8=sm.getSelections(); +if(dd.getDragData(e)){ +var _b9=dd.getDragData(e).rowIndex; +if(typeof (_b9)!="undefined"){ +if(!this.copy){ +for(i=0;i<_b8.length;i++){ +ds.remove(ds.getById(_b8[i].id)); +} +} +ds.insert(_b9,_b5.selections); +sm.clearSelections(); +} +} +}}); +this.filegrid.render(); +this.createGridPanel(this.filegrid,"center",{title:acs_lang_text.file_list||"File List",closable:false}); +} +this.filegrid.getDataSource().baseParams["folder_id"]=_a9.id; +if(_a9.loading){ +_a9.on("expand",function(){ +this.filegrid.getDataSource().load(); +}.createDelegate(this),true,{single:true}); +}else{ +this.filegrid.getDataSource().load(); +} +}; +this.renderTree=function(){ +var _ba=function(_bb,_bc,_bd){ +if(_bc){ +rootfolderobj=eval("("+_bd.responseText+")"); +this.rootfolder=new Ext.tree.AsyncTreeNode({text:rootfolderobj.text,draggable:false,id:rootfolderobj.id,singeClickExpand:true,attributes:rootfolderobj.attributes}); +if(rootfolderobj.attributes["write_p"]=="t"){ +this.toolbar=new Ext.Toolbar("headerpanel"); +this.toolbar.addButton({text:acs_lang_text.newfolder||"New Folder",icon:"/resources/ajax-filestorage-ui/icons/folder_add.png",cls:"x-btn-text-icon",handler:this.newFolder.createDelegate(this),scope:this}); +this.toolbar.addButton({text:acs_lang_text.uploadfile||"Upload Files",icon:"/resources/ajax-filestorage-ui/icons/add.png",cls:"x-btn-text-icon",handler:this.showUplddialog.createDelegate(this),scope:this}); +this.toolbar.addButton({text:acs_lang_text.createurl||"Create Url",icon:"/resources/ajax-filestorage-ui/icons/page_link.png",cls:"x-btn-text-icon",handler:this.showCreateUrldialog.createDelegate(this),scope:this}); +this.toolbar.addButton({text:acs_lang_text.deletefs||"Delete",icon:"/resources/ajax-filestorage-ui/icons/delete.png",cls:"x-btn-text-icon",handler:this.confirmDel.createDelegate(this),scope:this}); +}else{ +this.layout.getRegion("north").hide(); +} +this.treepanel.setRootNode(this.rootfolder); +this.treepanel.render(); +var _be=function(x){ +var _c0=this.treepanel.getNodeById(this.config.initOpenFolder); +if(!_c0){ +var x=x+1; +var _c1=this.config.pathToFolder[x]; +var _c2=this.treepanel.getNodeById(_c1); +_c2.on("expand",_be.createDelegate(this,[x]),this,{single:true}); +_c2.expand(true); +}else{ +_c0.select(); +_c0.fireEvent("click",_c0); +} +}; +var _c3=function(){ +if(this.config.initOpenFolder){ +var _c4=this.treepanel.getNodeById(this.config.initOpenFolder); +if(_c4){ +_c4.expand(); +_c4.fireEvent("click",_c4); +}else{ +var x=1; +var _c6=this.treepanel.getNodeById(this.config.pathToFolder[x]); +_c6.on("expand",_be.createDelegate(this,[x]),this,{single:true}); +_c6.expand(true); +} +}else{ +this.treepanel.fireEvent("click",this.rootfolder); +} +}; +this.rootfolder.on("expand",_c3,this,{single:true}); +this.rootfolder.expand(); +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",acs_lang_text.tree_render_error||"Sorry, we encountered an error rendering the tree panel"); +} +}; +var _c7="package_id="+this.config.package_id; +if(this.config.rootfolder){ +_c7=_c7+"&root_folder_id="+this.config.rootfolder; +} +this.asyncCon.request({url:this.xmlhttpurl+"getrootfolder",params:_c7,method:"POST",callback:_ba,scope:this}); +}; +this.loadTreepanel=function(){ +var _c8=Ext.get("folderpanel").createChild({tag:"div",id:"folders"}); +this.treepanel=new Ext.tree.TreePanel("folders",{animate:true,loader:new Ext.tree.TreeLoader({dataUrl:this.xmlhttpurl+"loadnodes",baseParams:{package_id:this.config.package_id}}),enableDD:true,ddGroup:"fileDD",ddAppendOnly:true,containerScroll:true,rootVisible:true}); +this.te=new Ext.tree.TreeEditor(this.treepanel,{allowBlank:false,blankText:acs_lang_text.folder_name_required||"A folder name is required",selectOnFocus:true}); +this.te.on("beforestartedit",function(_c9,el,_cb){ +if(_c9.editNode.attributes.attributes.write_p=="t"){ +return true; +}else{ +Ext.Msg.alert(acs_lang_text.permission_denied||"Permission Denied",acs_lang_text.permission_denied||"Sorry, you do not have permission to rename this folder"); +return false; +} +},this,true); +this.te.on("beforecomplete",function(_cc,_cd,_ce){ +var _cf=_cc.editNode.parentNode; +var _d0=_cf.childNodes; +for(x=0;x<_d0.length;x++){ +if(_d0[x].text==_cd&&_d0[x].id!=_cc.editNode.id){ +Ext.Msg.alert(acs_lang_text.duplicate_name||"Duplicate Name",acs_lang_text.duplicate_name_error||"Please enter a different name. The name you entered is already being used."); +return false; +} +} +return true; +},this,true); +this.te.on("complete",function(_d1,_d2,_d3){ +var _d4=function(_d5,_d6,_d7){ +var _d8=acs_lang_text.an_error_occurred||"An error occurred"; +var _d9=acs_lang_text.reverted||"Your changes have been reverted"; +if(_d6){ +if(_d7.responseText!=1){ +Ext.Msg.alert(acs_lang_text.error||"Error",_d8+":

"+_d7.responseText+"

"+_d9); +_d1.editNode.setText(_d3); +} +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",_d8+":

"+_d7.responseText+"

"+_d9); +_d1.editNode.setText(_d3); +} +}; +this.asyncCon.request({url:this.xmlhttpurl+"editname",params:"newname="+_d2+"&object_id="+_d1.editNode.id+"&type=folder",method:"POST",callback:_d4,scope:this}); +},this,true); +this.treepanel.on("click",this.loadFoldercontents,this,true); +this.treepanel.on("nodedragover",function(e){ +if(e.target.id==this.treepanel.getSelectionModel().getSelectedNode().id){ +return false; +} +if(e.source.dragData.selections){ +for(var x=0;x
"+_e5.responseText+"

"+_e8); +_e6=true; +} +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",acs_lang_text.error_and_reverted||"An error occurred. Your changes have been reverted"); +_e6=true; +} +if(_e6){ +_e3.target.removeChild(_e3.thenode); +_e3.parent.appendChild(_e3.thenode); +_e3.parent.loaded=false; +_e3.parent.expand(); +}else{ +_e3.target.loaded=false; +_e3.target.fireEvent("click",_e3.target); +_e3.target.expand(); +} +}; +var _e9="file_ids="+_e0+"&folder_target_id="+_e1; +var url=this.xmlhttpurl+"move"; +this.asyncCon.request({url:url,params:_e9,method:"POST",callback:_e2,scope:this,target:t,parent:p,thenode:n}); +}else{ +var _eb=_dc.target.id; +var _ec=[]; +for(var x=0;x<_dc.data.selections.length;x++){ +_ec[x]=_dc.data.selections[x].data.id; +if(_dc.data.selections[x].data.type=="folder"){ +if(this.treepanel.getNodeById(_dc.data.selections[x].data.id)){ +var _ee=this.treepanel.getNodeById(_dc.data.selections[x].data.id).parentNode; +_ee.loaded=false; +_ee.removeChild(this.treepanel.getNodeById(_dc.data.selections[x].data.id)); +} +} +} +var _e2=function(_ef,_f0,_f1){ +if(_f0&&_f1.responseText==1){ +var dm=this.filegrid.getDataSource(); +var _f3=this.filegrid.getSelectionModel().getSelections(); +for(var x=0;x<_f3.length;x++){ +dm.remove(_f3[x]); +} +_ef.target.loaded=false; +}else{ +Ext.Msg.alert(acs_lang_text.error||"Error",acs_lang_text.error_move||"Sorry, an error occurred moving this item. A file with the same name may already exist in the target folder."); +} +}; +var _e9="folder_target_id="+_eb+"&file_ids="+_ec; +var url=this.xmlhttpurl+"move"; +var _f5=new Ext.data.Connection(); +_f5.request({url:url,params:_e9,method:"POST",callback:_e2,scope:this,target:t}); +} +},this,true); +this.renderTree(); +}; +this.initLayout=function(){ +var _f6=document.body; +if(this.config!=null&&this.config.layoutdiv){ +_f6=this.config.layoutdiv; +} +this.layout=new Ext.BorderLayout(_f6,{north:{split:false,titlebar:false,autoScroll:false,initialSize:25},west:{autoScroll:true,split:true,initialSize:350,titlebar:true,collapsible:true,minSize:200,maxSize:500},center:{autoScroll:true}}); +this.layout.beginUpdate(); +this.layout.add("north",new Ext.ContentPanel("headerpanel",{autoCreate:true})); +this.layout.add("west",new Ext.ContentPanel("folderpanel",{autoCreate:true,autoScroll:true,fitToFrame:true,fitContainer:true})); +this.layout.endUpdate(); +var _f7={autoCreate:true,autoScroll:true,modal:false,autoTabs:true,width:300,height:300,shadow:false,shim:false,minWidth:300,minHeight:300,proxyDrag:true,fixedcenter:true}; +this.upldDialog=new Ext.BasicDialog("uploadDlg",_f7); +this.createurlDialog=new Ext.BasicDialog("urlDlg",_f7); +Ext.get(document.body).createChild({tag:"div",id:"files"}); +}; +this.initObj=function(){ +if(typeof (Ext.DomHelper)!="undefined"){ +if(_3f){ +this.config=_3f; +if(!this.config.ispublic){ +this.asyncCon.on("requestcomplete",this.isSessionExpired,this); +} +} +this.initLayout(); +this.loadTreepanel(); +} +}; +Ext.EventManager.onDocumentReady(this.initObj,this,true); +} + Index: openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.css =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.css,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.css 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.css 8 Sep 2007 14:32:55 -0000 1.3 @@ -1,61 +1,84 @@ -body {font:normal 9pt verdana; margin:0;padding:0;border:0px none;overflow:hidden;} -#header{ - border-bottom: 1px solid #083772; - padding:5px 4px; - color:#ffffff; - background: rgb(133, 174, 236) url(/resources/ajaxhelper/dojo-ajax/src/widget/templates/images/soriaAccordionSelected.gif); -} -#footer{ - background: url(images/header-bar.gif) repeat-x bottom; - border-top: 1px solid #083772; - padding:2px 4px; - color:white; - font:normal 8pt arial,helvetica; -} -#folders, #files, #fileinfo { - padding:10px; -} -#folders { - padding-top :0; - padding-left: 5px; -} -#files { - padding-top :0; -} -#content p { - margin:5px; -} -#folders li { - padding:2px; - padding-left:10px; - background-image:url(images/bullet.gif); - background-position: -3px 6px; - background-repeat: no-repeat; - font-size:8pt; - display: block; -} -.ylayout-panel-north, .ylayout-panel-south, #content .ylayout-panel-center{ - border:0px none; -} -#content .ylayout-panel-south{ - border-top:1px solid #aca899; -} -#content .ylayout-panel-center{ - border-bottom:1px solid #aca899; -} -#fileheader { - padding: 3px; -} -#fileheader td a { - font-size: 10px; - text-align: center; -} -.statusmsg { - color: #cccccc; - text-align: center; - font-weight: bold; -} -.folderselected { - background-color:blue; - color:white; -} \ No newline at end of file + .x-tree-node img.folder, .x-tree-node-collapsed img.folder{ + background: url(/resources/ajaxhelper/ext/resources/images/default/tree/folder.gif) + } + .x-tree-node-expanded img.folder { + background: url(/resources/ajaxhelper/ext/resources/images/default/tree/folder-open.gif) + } + .x-tree-grayselected a span{ + background:#e2e2e2; + } + .onerow { + padding:5px; + vertical-align: middle; + cursor:pointer; + } + .onerow td a { + text-decoration: none; + color:#000000; + } + #filepanel { + font-family: arial,tahoma,helvetica,sans-serif; + font-size: 11px; + } + #filepanel .x-view-selected { + background-color: #C3DAF9; + } + div.flash + { + width: 80%; + margin: 10px 0px 10px 0px; + border-color: #D9E4FF; + } + .progressName { + font-size: 8pt; + font-weight: bold; + color: #555555; + + width: 80%; + height: 14px; + text-align: left; + white-space: nowrap; + overflow: hidden; + } + .progressBarInProgress, + .progressBarComplete, + .progressBarError { + font-size: 0px; + width: 0%; + height: 2px; + background-color: blue; + margin-top: 2px; + } + .progressBarComplete { + width: 100%; + background-color: green; + visibility: hidden; + } + .progressBarError { + width: 100%; + background-color: red; + visibility: hidden; + } + .progressBarStatus { + margin-top: 2px; + width: 80%; + font-size: 7pt; + font-family: Verdana; + text-align: left; + white-space: nowrap; + } + a.progressCancel, + a.progressCancel:link, + a.progressCancel:active, + a.progressCancel:visited, + a.progressCancel:hover + { + font-size: 0px; + display: block; + height: 20px; + width: 20px; + + background-image: url(/resources/ajax-filestorage-ui/icons/delete.png); + background-repeat: no-repeat; + float: right; + } \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.js =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.js,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.js 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/resources/ajaxfs.js 8 Sep 2007 14:32:55 -0000 1.3 @@ -1,312 +1,1497 @@ -/* loadJs -helper that executes anything that is between script tags - in a responseText returned by an ajax call */ +/* + Ajax File Storage + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-06-03 +*/ -function loadJs(responseText) { - var re=/(?:.*<\/script>)|(?:([\S\s]*?)<\/script>)/ig; - var match; - while (match = re.exec(responseText)) { - var s0 = document.createElement("script"); - if (match[1]) - s0.src = match[1]; - else if (match[2]) - s0.text = match[2]; - else - continue; - document.getElementsByTagName("head")[0].appendChild(s0); +/********** UTILS *********************/ + +/* readCookie +read value of a cookie */ +function readCookie(name) { + var ca = document.cookie.split(';'); + var nameEQ = name + "="; + for(var i=0; i < ca.length; i++) { + var c = ca[i]; + while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces + if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length); + } + return null; +} + +/* createCookie +used to maintain state, e.g. when login expires */ +function createCookie(name, value, days){ + if (days) { + var date = new Date(); + date.setTime(date.getTime()+(days*24*60*60*1000)); + var expires = "; expires="+date.toGMTString(); + } + else var expires = ""; + document.cookie = name+"="+value+expires+"; path=/"; +} + +/* read query string +read the value of a querystring */ +function readQs(q) { + var query = window.location.search.substring(1); + var parms = query.split('&'); + for (var i=0; i 0) { + var key = parms[i].substring(0,pos); + var val = parms[i].substring(pos+1); + if (key == q) { + return val; + } } + } + return null; } -/* trimString -helper to remove trailing and leading spaces from a string */ -function trimString (str) { - str = this != window? this : str; - return str.replace(/^\s+/g, '').replace(/\s+$/g, ''); +/* check Flash Version */ +function checkFlashVersion() { + + var x; + var pluginversion; + + if(navigator.plugins && navigator.mimeTypes.length){ + x = navigator.plugins["Shockwave Flash"]; + if(x && x.description) x = x.description; + } else if (Ext.isIE){ + try { + x = new ActiveXObject("ShockwaveFlash.ShockwaveFlash"); + x = x.GetVariable("$version"); + } catch(e){} + } + + pluginVersion = (typeof(x) == 'string') ? parseInt(x.match(/\d+/)[0]) : 0; + + return pluginVersion; } -/* editInPlace -dynamically make the properties_name element editable*/ +// check if the string argument is a url +function isURL(argvalue) { -function editInPlace (objid,namediv,controldiv,type) { - this.objid = objid - this.namediv = document.getElementById(namediv); - this.controldiv = document.getElementById(controldiv); - this.oldnamediv_value = this.namediv.innerHTML; - this.oldcontroldiv_value = this.controldiv.innerHTML; - this.form_textbox = 'edip_name'; - this.form_ok = 'edip_save'; - this.form_cancel = 'edip_cancel'; - this.type = type; - this.setvalues = function (nameval,controlval) { - this.namediv.innerHTML = nameval; - this.controldiv.innerHTML = controlval; + if (argvalue.indexOf(" ") != -1) + return false; + else if (argvalue.indexOf("http://") == -1) + return false; + else if (argvalue == "http://") + return false; + else if (argvalue.indexOf("http://") > 0) + return false; + + argvalue = argvalue.substring(7, argvalue.length); + if (argvalue.indexOf(".") == -1) + return false; + else if (argvalue.indexOf(".") == 0) + return false; + else if (argvalue.charAt(argvalue.length - 1) == ".") + return false; + + if (argvalue.indexOf("/") != -1) { + argvalue = argvalue.substring(0, argvalue.indexOf("/")); + if (argvalue.charAt(argvalue.length - 1) == ".") + return false; + } + + if (argvalue.indexOf(":") != -1) { + if (argvalue.indexOf(":") == (argvalue.length - 1)) + return false; + else if (argvalue.charAt(argvalue.indexOf(":") + 1) == ".") + return false; + argvalue = argvalue.substring(0, argvalue.indexOf(":")); + if (argvalue.charAt(argvalue.length - 1) == ".") + return false; + } + + return true; + +} + +/********** FLASH UPLOAD *********/ + + +function FileProgress(fileObj, target_id) { + this.file_progress_id = fileObj.id; + + this.opacity = 100; + this.height = 0; + + this.fileProgressWrapper = document.getElementById(this.file_progress_id); + if (!this.fileProgressWrapper) { + this.fileProgressWrapper = document.createElement("div"); + this.fileProgressWrapper.className = "progressWrapper"; + this.fileProgressWrapper.id = this.file_progress_id; + + this.fileProgressElement = document.createElement("div"); + this.fileProgressElement.className = "progressContainer"; + + var progressCancel = document.createElement("a"); + progressCancel.className = "progressCancel"; + progressCancel.href = "#"; + progressCancel.style.visibility = "hidden"; + progressCancel.appendChild(document.createTextNode(" ")); + + var progressText = document.createElement("div"); + progressText.className = "progressName"; + progressText.appendChild(document.createTextNode(fileObj.name)); + + var progressBar = document.createElement("div"); + progressBar.className = "progressBarInProgress"; + + var progressStatus = document.createElement("div"); + progressStatus.className = "progressBarStatus"; + progressStatus.innerHTML = " "; + + this.fileProgressElement.appendChild(progressCancel); + this.fileProgressElement.appendChild(progressText); + this.fileProgressElement.appendChild(progressStatus); + this.fileProgressElement.appendChild(progressBar); + + this.fileProgressWrapper.appendChild(this.fileProgressElement); + + document.getElementById(target_id).appendChild(this.fileProgressWrapper); + } else { + this.fileProgressElement = this.fileProgressWrapper.firstChild; } - this.addListeners = function() { - thisobj =this; - YAHOO.util.Event.addListener(this.form_ok, "click", this.saveedit,thisobj); - YAHOO.util.Event.addListener(this.form_cancel, "click", this.canceledit,thisobj); + + this.height = this.fileProgressWrapper.offsetHeight; + +} +FileProgress.prototype.SetProgress = function(percentage) { + this.fileProgressElement.className = "progressContainer green"; + this.fileProgressElement.childNodes[3].className = "progressBarInProgress"; + this.fileProgressElement.childNodes[3].style.width = percentage + "%"; +} +FileProgress.prototype.SetComplete = function() { + this.fileProgressElement.className = "progressContainer blue"; + this.fileProgressElement.childNodes[3].className = "progressBarComplete"; + this.fileProgressElement.childNodes[3].style.width = ""; + + var oSelf = this; + setTimeout(function() { oSelf.Disappear(); }, 10000); +} +FileProgress.prototype.SetError = function() { + this.fileProgressElement.className = "progressContainer red"; + this.fileProgressElement.childNodes[3].className = "progressBarError"; + this.fileProgressElement.childNodes[3].style.width = ""; + + var oSelf = this; + setTimeout(function() { oSelf.Disappear(); }, 5000); +} +FileProgress.prototype.SetCancelled = function() { + this.fileProgressElement.className = "progressContainer"; + this.fileProgressElement.childNodes[3].className = "progressBarError"; + this.fileProgressElement.childNodes[3].style.width = ""; + + var oSelf = this; + setTimeout(function() { oSelf.Disappear(); }, 2000); +} +FileProgress.prototype.SetStatus = function(status) { + this.fileProgressElement.childNodes[2].innerHTML = status; +} + +FileProgress.prototype.ToggleCancel = function(show, upload_obj) { + this.fileProgressElement.childNodes[0].style.visibility = show ? "visible" : "hidden"; + if (upload_obj) { + var file_id = this.file_progress_id; + this.fileProgressElement.childNodes[0].onclick = function() { upload_obj.cancelUpload(file_id); return false; }; } - this.rmListeners = function() { - thisobj =this; - YAHOO.util.Event.removeListener(this.form_ok, "click", this.saveedit,thisobj); - YAHOO.util.Event.removeListener(this.form_cancel, "click", this.canceledit,thisobj); +} + +FileProgress.prototype.Disappear = function() { + + var reduce_opacity_by = 15; + var reduce_height_by = 4; + var rate = 30; // 15 fps + + if (this.opacity > 0) { + this.opacity -= reduce_opacity_by; + if (this.opacity < 0) this.opacity = 0; + + if (this.fileProgressWrapper.filters) { + try { + this.fileProgressWrapper.filters.item("DXImageTransform.Microsoft.Alpha").opacity = this.opacity; + } catch (e) { + // If it is not set initially, the browser will throw an error. This will set it if it is not set yet. + this.fileProgressWrapper.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=' + this.opacity + ')'; + } + } else { + this.fileProgressWrapper.style.opacity = this.opacity / 100; + } } - this.createform = function() { - var editform = ""; - editform = editform + " "; - editform = editform + ""; - this.setvalues(editform,''); - document.getElementById('edip_name').select(); - this.addListeners(); + + if (this.height > 0) { + this.height -= reduce_height_by; + if (this.height < 0) this.height = 0; + + this.fileProgressWrapper.style.height = this.height + "px"; } - this.canceledit = function(el,obj) { - obj.rmListeners(); - obj.setvalues(obj.oldnamediv_value,obj.oldcontroldiv_value); + + if (this.height > 0 || this.opacity > 0) { + var oSelf = this; + setTimeout(function() { oSelf.Disappear(); }, rate); + } else { + this.fileProgressWrapper.style.display = "none"; } - this.saveedit = function(el,obj) { - // save the new name - var postData ='type='+obj.type+'&object_id='+obj.objid+'&newname='+document.getElementById(obj.form_textbox).value; - var callback = { - success: function(o) { - obj.namediv.innerHTML=o.responseText; - obj.controldiv.innerHTML=obj.oldcontroldiv_value; +} - // check if node exists in tree - if ( tree != 'undefined') { - var node = tree.getNodeByProperty('id',obj.objid); - // update node name - if ( node != null) { - document.getElementById(node.getLabelEl().id).innerHTML=o.responseText; - } - } +function uploadStart(fileObj,ajaxfsobj) { + var upload_txt = acs_lang_text.for_upload_to || "for upload to"; + var zip_txt = acs_lang_text.zip_extracted || "Zip File (Will be extracted after upload)"; + try { + // You might include code here that prevents the form from being submitted while the upload is in + // progress. Then you'll want to put code in the Queue Complete handler to "unblock" the form + var folderid = ajaxfsobj.currentfolder; + var foldername = ajaxfsobj.treepanel.getNodeById(folderid).text; + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetStatus( upload_txt + ""+foldername+"
"+ zip_txt); + progress.ToggleCancel(true, this); + this.addFileParam(fileObj.id, "folder_id", folderid); + ajaxfsobj.upldDialog.buttons[0].enable(); + } catch (ex) { this.debugMessage(ex); } +} - }, argument: { thisobj:obj } +function uploadProgress(fileObj, bytesLoaded) { + try { + var percent = Math.ceil((bytesLoaded / fileObj.size) * 100) + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetProgress(percent); + progress.SetStatus(acs_lang_text.uploading || "Uploading..."); + } catch (ex) { this.debugMessage(ex); } +} + +function uploadFileComplete(fileObj) { + try { + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetComplete(); + progress.SetStatus(acs_lang_text.complete || "Complete."); + progress.ToggleCancel(false); + + } catch (ex) { this.debugMessage(ex); } +} + +function uploadComplete(fileObj) { + try { + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetComplete(); + progress.SetStatus(acs_lang_text.complete || "Complete."); + progress.ToggleCancel(false); + + } catch (ex) { this.debugMessage(ex); } +} + +function uploadQueueComplete(fileidx,ajaxfsobj) { + ajaxfsobj.upldDialog.buttons[0].disable(); + var currentTreeNode = ajaxfsobj.treepanel.getNodeById(ajaxfsobj.currentfolder); + currentTreeNode.fireEvent("click",currentTreeNode); +} + +function uploadError(error_code, fileObj, message) { + try { + if (error_code == SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED) { + Ext.Msg.alert(acs_lang_text.alert || "Alert","You have attempted to queue too many files.\n" + (message == 0 ? "You have reached the upload limit." : "You may select " + (message > 1 ? "up to " + message + " files." : "one file."))); + return; } - YAHOO.util.Connect.asyncRequest('POST', '/ajaxfs/xmlhttp/editname', callback, postData); + + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetError(); + progress.ToggleCancel(false); + + switch(error_code) { + case SWFUpload.ERROR_CODE_HTTP_ERROR: + progress.SetStatus("Upload Error"); + this.debugMessage("Error Code: HTTP Error, File name: " + file.name + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET: + progress.SetStatus("Configuration Error"); + this.debugMessage("Error Code: No backend file, File name: " + file.name + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_UPLOAD_FAILED: + progress.SetStatus("Upload Failed."); + this.debugMessage("Error Code: Upload Failed, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_IO_ERROR: + progress.SetStatus("Server (IO) Error"); + this.debugMessage("Error Code: IO Error, File name: " + file.name + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_SECURITY_ERROR: + progress.SetStatus("Security Error"); + this.debugMessage("Error Code: Security Error, File name: " + file.name + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT: + progress.SetStatus("File is too big."); + this.debugMessage("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE: + progress.SetStatus("Cannot upload Zero Byte files."); + this.debugMessage("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); + break; + case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED: + progress.SetStatus("Upload limit exceeded."); + this.debugMessage("Error Code: Upload Limit Exceeded, File name: " + file.name + ", File size: " + file.size + ", Message: " + message); + break; + default: + progress.SetStatus("Unhandled Error"); + this.debugMessage("Error Code: " + error_code + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message); + break; + } + } catch (ex) { + this.debugMessage(ex); } - this.createform(); } -/* showFolderContents -Called when a folder is clicked, fetches all the files and folders in a node */ +function uploadCancel(fileObj) { + try { + var progress = new FileProgress(fileObj, this.getSetting("progress_target")); + progress.SetCancelled(); + progress.SetStatus(acs_lang_text.uploadcancel || "Cancelled (This item will be removed shortly)"); + progress.ToggleCancel(false); -function showFolderContents(folder_id,tree,sort) { + } + catch (ex) { + this.debugMessage(ex); + } +} - // show 'loading...' - document.getElementById('files').innerHTML = '


Loading . . . . .
'; +/********** AjaxFS Objects ***********/ - // expand the tree on click - var thenode = tree.getNodeByProperty('id',folder_id); +function ajaxfs(configObj) { - // remove highlight from the last folder - if ( document.getElementById('lastfolder').value != "" ) { - if (tree.getNodeByProperty('id',document.getElementById('lastfolder').value) != null ) { - var oldnode = tree.getNodeByProperty('id',document.getElementById('lastfolder').value); - YAHOO.util.Dom.removeClass(oldnode.getLabelEl().id,'folderselected'); - } - } + // ** configObj ** + // ajaxFs expects a config object that may have the following properites + // configObj.package_ids : the package_id or a comma separated list of package_ids of the current ajaxFs Instance + // configObj.initOpenFolder : if this value is not null, it should contain the folder id to open when object is instantiated + // configOjb.layoutdiv : the div container where we put the layout, if none is provided then document.body is used - // open or close the node - thenode.toggle(); + // ** properties ** - // write this node's id to the hidden field - document.getElementById('lastfolder').value = folder_id; + // where to get - // let's highlight the new selected folder - var newnode = tree.getNodeByProperty('id',document.getElementById('lastfolder').value); - YAHOO.util.Dom.addClass(newnode.getLabelEl().id,'folderselected'); + // url of xmlhttp files from ajaxfs + this.xmlhttpurl = '/ajaxfs2/xmlhttp/'; - // empty the items in the fsList object_id - fileList.emptyItems(); + // holds an object with configruation settings for this instance + // of ajaxfs, this variable is set only if configObj exists and is passed + this.config = null; - // fetch contents via ajax - var postData ='folder_id='+folder_id+'&orderby='+sort; - var callback = { - success: function(o) { - document.getElementById('files').innerHTML=o.responseText; - loadJs(o.responseText); - } - } - YAHOO.util.Connect.asyncRequest('POST', '/ajaxfs/xmlhttp/showfoldercontents', callback, postData); + // holds a reference to the layout for the center page + this.layout = null; - showProperties(folder_id,'folder'); -} + // holds a reference to the tree panel + this.treepanel = null; -/* showProperties -Populates the action and properties panel with more information and actions*/ + // holds a reference to the tree editor + this.te = null; -function showProperties (object_id,type) { + // holds a reference to the root of the tree + this.rootfolder = null; - var southpanel = innerLayout.getRegion('south'); - southpanel.setActivePanel('properties'); + // the grid that lists the files + this.filegrid = null; - // fetch contents of properites - var postData ='object_id='+object_id+'&type='+type; - var callback = { - success: function(o) { - loadJs(o.responseText); - document.getElementById('properties').innerHTML=o.responseText; + // holds a reference to the toolbar + this.toolbar = null; + + // holds the id of the currently selected node in the tree + this.currentfolder = null; + + // reusable aync data connection + this.asyncCon = new Ext.data.Connection(); + + // reference to messagebox + this.msgbox = Ext.MessageBox; + + // create upload dialog + this.upldDialog = null; + + // create ur dialog + this.createurlDialog = null; + + // permissions dialog + this.permsDialog = null; + + /// revisions dialog + this.revisionsDialog = null; + + // reference to contextmenu + this.contextmenu = null; + + // reference to an instance of the swfuploader + // used for ajaxfs + this.swfu = null; + + // ** methods ** + + // check if the string has the login form + // redirects to login form if true, does nothing if not + this.isSessionExpired = function() { + // check if the string has method="post" name="login" + if ( readCookie("ad_user_login") == null ) { + Ext.get(document.body).mask(acs_lang_text.sessionexpired || "Your session has expired. You need to login again.
You will be redirected to a login page shortly"); + var params = "package_id="+this.config.package_id; + if(this.currentfolder != null) { + params = params + "&folder_id="+this.currentfolder; + } + window.location="/register/?return_url="+window.location; + return 1 } + return 0 } - YAHOO.util.Connect.asyncRequest('POST', '/ajaxfs/xmlhttp/showproperties', callback, postData); - if (type === "folder" ) { - southpanel.hidePanel('revisions'); - } else { - southpanel.unhidePanel('revisions'); - // TODO : use ajax to fetch revisions table of the object + // check the permissions, returns either true or false + this.isPermitted = function(objid,perm) { + + var callback = function(option,success,response) { + if(success) { + return response.responseText; + } else { + return 0; + } + } + + this.asyncCon.request({url:this.xmlhttpurl+"checkperms", + params: "object_id="+objid+"&perm="+perm, + method:"POST", + callback: callback, + scope: this + }); + } -} -/* loadDataForNode -Dynamically loads the child nodes of a given parent node*/ + // creates a gridpanel + this.createGridPanel = function(grid,region,configObj) { + // create the grid panel + gridPanel = new Ext.GridPanel(grid, configObj) + this.layout.add(region, gridPanel); + } -function loadDataForNode(node, onCompleteCallback) { + // generates a url to the currently selected file storage item + // if it's a file : download + // if it's a folder : append folder_id to the current url + this.linkCopy = function() { + var node = this.filegrid.getSelectionModel().getSelected(); + var nodetype = node.get("type"); + if (nodetype === "folder") { + // generate the url to a folder + var copytext = window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"?package_id="+this.config.package_id+"&folder_id="+node.get("id"); + } else if (nodetype === "url") { + var copytext = node.get("url"); + } else { + var copytext = window.location.protocol+"//"+window.location.hostname+node.get("url"); + } + if(Ext.isIE) { + window.clipboardData.setData("text",copytext); + } else { + var copyprompt = Ext.Msg.show({ + title: acs_lang_text.linkaddress || 'Copy Link Address', + prompt: true, + msg: acs_lang_text.copyhighlighted || 'Copy the highlighted text to your clipboard.', + value: copytext, + buttons: Ext.Msg.OK + }); + var prompt_text_el = YAHOO.util.Dom.getElementsByClassName('ext-mb-input', 'input','x-msg-box'); + prompt_text_el[0].select(); + } + } - var postData ='parentfolderid='+node.data.id; - var callback = { - success: function(o) { - eval(o.responseText); - onCompleteCallback(); - }, failure: function(o) { - alert('Error ' + o.status + ' -- ' + o.statusText); - onCompleteCallback(); - } - } + // rename a file or folder in the right panel + this.fileRename = function() { - YAHOO.util.Connect.asyncRequest('POST', '/ajaxfs/xmlhttp/loadchildnodes', callback, postData); -} + var node = this.filegrid.getSelectionModel().getSelected(); + var nodeurl = node.get("url"); + var nodetype = node.get("type"); + var nodeid = node.get("id"); + var nodesubtitle = node.get("filename"); -/* openfolder -Opens a node in the folder tree */ + var handleRename = function(btn, text) { + if(btn=='ok') { + if(text != '') { + if(text.length > 100) { + Ext.Msg.alert(acs_lang_text.alert || "Alert",acs_lang_text.limitto100 || "Please limit your name to 100 characters or less."); + return false; + } else { + var callback = function(option,success,response) { + var err_msg_txt = acs_lang_text.an_error_occurred || "An error occurred"; + var err_msg_txt2 = acs_lang_text.reverted || "Your changes have been reverted"; + if (success) { + if (response.responseText != 1) { + Ext.Msg.alert(acs_lang_text.error || "Error",err_msg_txt + ":

"+response.responseText+"

"+err_msg_txt2); + } else { + if(nodetype!="folder"&&nodesubtitle===" ") { nodesubtitle = node.get("title") } + if(nodetype=="folder") { this.treepanel.getNodeById(nodeid).setText(text) } + node.set("title",text); + node.set("title_and_name",""+text+"
"+nodesubtitle+"") + node.commit(); + } + } else { + Ext.Msg.alert(acs_lang_text.error || "Error",err_msg_text+":

"+response.responseText+"

"+err_msg_txt2); + } + } + + this.asyncCon.request({url:this.xmlhttpurl+"editname", + params: "newname="+text+"&object_id="+nodeid+"&type="+nodetype+"&url="+nodeurl, + method:"POST", + callback: callback, + scope: this + }); + } + } else { + Ext.Msg.alert(acs_lang_text.alert || "Alert",acs_lang_text.enter_new_name || "Please enter a new name."); + return false; + } + } + } -function openfolder(object_id) { - // get a reference to the node for the given object_id - var thenode = tree.getNodeByProperty('id',object_id); - thenode.parent.expand(); - showFolderContents(object_id,tree,'name'); -} + // Ext.MessageBox.prompt('Rename', 'Please enter a new name for
'+view.jsonData[node.nodeIndex].title+':', handleRename.createDelegate(this)); + Ext.Msg.show({ + title: acs_lang_text.rename || 'Rename', + prompt: true, + msg: acs_lang_text.enter_new_name || 'Please enter a new name for ... ', + value: node.get("title"), + buttons: Ext.Msg.OKCANCEL, + fn: handleRename.createDelegate(this) + }); + var prompt_text_el = YAHOO.util.Dom.getElementsByClassName('ext-mb-input', 'input','x-msg-box'); + prompt_text_el[0].select(); + } -/* ajaxFsLayout -Prototype Object to generate the layout */ + // permissions dialog + this.permsRedirect = function() { + var node = this.filegrid.getSelectionModel().getSelected(); + var object_id = node.get("id"); + var newwindow = window.open(window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"permissions?object_id="+object_id+"&return_url="+window.location.pathname+"?package_id="+this.config.package_id+"&folder_id="+this.currentfolder); + newwindow.focus(); + } -var layout; -var innerLayout; + // redirect to file properties + this.propertiesRedirect = function() { + var node = this.filegrid.getSelectionModel().getSelected(); + var object_id = node.get("id"); + var newwindow = window.open(window.location.protocol+"//"+window.location.hostname+":"+window.location.port+this.config.package_url+"file?file_id="+object_id); + newwindow.focus(); + } -ajaxFsLayout = function() { - return { - init : function() { - layout = new YAHOO.ext.BorderLayout(document.body, { - hideOnLayout: true, - north: { - split:false, - initialSize: 25, - titlebar: false - }, - west: { - split:true, - initialSize: 300, - titlebar: true, - collapsible: true, - minSize: 100, - maxSize: 400 - }, - center: { - autoScroll: false + // generate a context bar + this.showContext = function(grid,i,e) { + e.stopEvent(); + if(this.contextmenu == null) { + // create the menus + this.contextmenu = new Ext.menu.Menu({ + id: 'rightclickmenu', + items: [ + new Ext.menu.Item({ + text: acs_lang_text.deletefs || 'Delete', + icon: '/resources/ajax-filestorage-ui/icons/delete.png', + handler: this.confirmDel.createDelegate(this) + }), + new Ext.menu.Item({ + text: acs_lang_text.rename || 'Rename', + icon: '/resources/ajax-filestorage-ui/icons/page_edit.png', + handler: this.fileRename.createDelegate(this) + }), + new Ext.menu.Item({ + text: acs_lang_text.linkaddress || 'Copy Link Address', + icon: '/resources/ajax-filestorage-ui/icons/page_copy.png', + handler: this.linkCopy.createDelegate(this) + }), + new Ext.menu.Item({ + text: acs_lang_text.permissions || 'Permissions', + icon: '/resources/ajax-filestorage-ui/icons/group_key.png', + handler: this.permsRedirect.createDelegate(this) + }), + new Ext.menu.Item({ + text: acs_lang_text.properties || 'Properties', + icon: '/resources/ajax-filestorage-ui/icons/page_edit.png', + handler: this.propertiesRedirect.createDelegate(this) + }) ] + }); + + } + // disable rename, copy link, permissions and revisions if more than one node item from the view is selected + if (grid.getSelectionModel().getCount() > 1) { + this.contextmenu.items.items[1].disable(); + this.contextmenu.items.items[2].disable(); + this.contextmenu.items.items[3].disable(); + this.contextmenu.items.items[4].disable(); + } else { + this.contextmenu.items.items[1].enable(); + this.contextmenu.items.items[2].enable(); + this.contextmenu.items.items[3].enable(); + var node = this.filegrid.getSelectionModel().getSelected(); + var object_type = node.get("type"); + if (object_type == "folder" || object_type == "url") { + this.contextmenu.items.items[4].disable(); + } else { + this.contextmenu.items.items[4].enable(); + } + } + + var coords = e.getXY(); + this.contextmenu.rowid = i; + this.contextmenu.showAt([coords[0], coords[1]]); + } + + // handle file upload + this.uploadFile = function(e) { + + if(document.getElementById("upload_file").value != "" && document.getElementById("filetitle").value != "") { + + var callback = { + success: function() { + }, upload: function() { + this.treepanel.getSelectionModel().getSelectedNode().loaded=false; + this.treepanel.getSelectionModel().getSelectedNode().fireEvent("click",this.treepanel.getSelectionModel().getSelectedNode()); + this.upldDialog.getEl().unmask(); + this.upldDialog.hide(); + }, failure: function() { + Ext.Msg.alert(acs_lang_text.error || "Error", acs_lang_text.upload_failed || "Upload failed, please try again later."); + }, scope: this + } + + var loading_msg = acs_lang_text.loading || "One moment. This may take a while depending on how large your upload is." + this.upldDialog.getEl().mask(" "+loading_msg); + + YAHOO.util.Connect.setForm("newfileform", true, true); + + var cObj = YAHOO.util.Connect.asyncRequest("POST", this.xmlhttpurl+"file-add", callback); + + } else { + + Ext.Msg.alert(acs_lang_text.alert || "Alert", acs_lang_text.file_required || "Title and File to upload are required."); + + } + } + + // create the url + this.createUrl = function(e) { + if(document.getElementById("fsurl").value != "" && document.getElementById("fstitle").value != "") { + if (isURL(document.getElementById("fsurl").value)) { + var callback = { + success: function() { + this.treepanel.getSelectionModel().getSelectedNode().loaded=false; + this.treepanel.getSelectionModel().getSelectedNode().fireEvent("click",this.treepanel.getSelectionModel().getSelectedNode()); + this.createurlDialog.getEl().unmask(); + this.createurlDialog.hide(); + },failure: function() { + this.createurlDialog.getEl().unmask(); + Ext.Msg.alert(acs_lang_text.error || "Error",acs_lang_text.createurl_failed || "Create URL failed, please try again later."); + }, scope: this } + + this.createurlDialog.getEl().mask(" One moment."); + + YAHOO.util.Connect.setForm("simple-add"); + + var cObj = YAHOO.util.Connect.asyncRequest("POST", this.xmlhttpurl+"url-add", callback); + } else { + Ext.Msg.alert(acs_lang_text.alert || "Alert", acs_lang_text.invalid_url || "URL is not a valid url."); + } + } else { + + Ext.Msg.alert(acs_lang_text.alert || "Alert", acs_lang_text.invalid_url || "Title and URL are required."); + + } + } + + // shows the create url dialog + this.showCreateUrldialog = function() { + if(!this.createurlDialog.buttons) { + this.createurlDialog.addButton({text:acs_lang_text.ok || 'Ok',icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"}, this.createUrl, this); + this.createurlDialog.addButton({text:acs_lang_text.cancel ||'Cancel',icon:"/resources/ajax-filestorage-ui/icons/cancel.png",cls:"x-btn-text-icon"}, this.createurlDialog.hide, this.createurlDialog); + } + this.createurlDialog.setTitle(acs_lang_text.createurl || "Create URL"); + this.createurlDialog.body.update("

Title


URL


Description :

"); + this.createurlDialog.body.setStyle("font","normal 12px tahoma, arial, helvetica, sans-serif"); + this.createurlDialog.body.setStyle("background-color","#ffffff"); + this.createurlDialog.body.setStyle("border","1px solid #e2e2e2"); + this.createurlDialog.body.setStyle("padding","3px"); + this.createurlDialog.show(); + } + + // shows the upload dialog, + // check if user has flash 8 or higher + // creates the upload form or + // shows the flash upload dialog + this.showUplddialog = function() { + this.upldDialog.setTitle(acs_lang_text.uploadfile || "Upload Files"); + if(checkFlashVersion() < 8) { + var msg1=acs_lang_text.file_to_upload || "File to upload"; + var msg2=acs_lang_text.file_title || "Title"; + var msg3=acs_lang_text.file_description || "Description"; + var msg4=acs_lang_text.multiple_files || "Multiple Files"; + var msg5=acs_lang_text.multiple_files_msg || "This is a ZIPfile containing multiple files."; + this.upldDialog.body.update("

"+msg1+"


"+msg2+"


"+msg3+" :

"+msg4+" :

"+msg5+"

"); + if(!this.upldDialog.buttons) { + this.upldDialog.addButton({text:acs_lang_text.upload || 'Upload',icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"}, this.uploadFile, this); + this.upldDialog.addButton({text:acs_lang_text.cancel || 'Cancel',icon:"/resources/ajax-filestorage-ui/icons/cancel.png",cls:"x-btn-text-icon"}, this.upldDialog.hide, this.upldDialog); + } + } else { + if(this.swfu == null) { + var err_msg_txt = acs_lang_text.upload_intro || "Click Browse to select a file to upload to the selected folder."; + this.upldDialog.body.update("
"+err_msg_txt+"
"); + var package_id = String(this.config.package_id); + var user_id = String(this.config.user_id); + var folder_id = String(this.currentfolder); + var max_file_size = String(this.config.max_file_size) || 5000000; + this.swfu = new SWFUpload({ + debug: false, + upload_target_url: "/ajaxfs2/xmlhttp/file-add-flash", + upload_params: {user_id:user_id,package_id:package_id}, + file_types : "*.*", + file_size_limit : max_file_size, + file_queue_limit : 3, + begin_upload_on_queue: false, + file_progress_handler : uploadProgress, + file_cancelled_handler : uploadCancel, + file_complete_handler : uploadComplete, + queue_complete_handler : uploadQueueComplete, + error_handler : uploadError, + flash_url : "/resources/ajax-filestorage-ui/swfupload/swfupload.swf" + }); + this.swfu.fileQueued = uploadStart.createDelegate(this.swfu,[this],true); + this.swfu.fileProgress = uploadProgress.createDelegate(this.swfu,[this],true); + this.swfu.fileComplete = uploadComplete.createDelegate(this.swfu,[this],true); + this.swfu.fileCancelled = uploadCancel.createDelegate(this.swfu,[this],true); + this.swfu.queueComplete = uploadQueueComplete.createDelegate(this.swfu,[this],true); + this.swfu.addSetting("progress_target", "fsuploadprogress"); + this.upldDialog.addButton({text:acs_lang_text.upload || 'Upload',disabled:true,icon:"/resources/ajax-filestorage-ui/icons/arrow_up.png",cls:"x-btn-text-icon"}, this.swfu.startUpload.createDelegate(this.swfu,[null,this],false), this); + this.upldDialog.addButton({text:acs_lang_text.browse || 'Browse',icon:"/resources/ajax-filestorage-ui/icons/page_add.png",cls:"x-btn-text-icon"}, this.swfu.browse, this.swfu); + this.upldDialog.addButton({text:acs_lang_text.close || 'Close',icon:"/resources/ajax-filestorage-ui/icons/cross.png",cls:"x-btn-text-icon"}, this.upldDialog.hide, this.upldDialog); + } + } + this.upldDialog.body.setStyle("font","normal 12px tahoma, arial, helvetica, sans-serif"); + this.upldDialog.body.setStyle("background-color","#ffffff"); + this.upldDialog.body.setStyle("border","1px solid #e2e2e2"); + this.upldDialog.body.setStyle("padding","3px"); + this.upldDialog.show(); + } + + // determine whether to delete from the jsonview or from the tree + this.confirmDel = function() { + var err_msg_txt = acs_lang_text.confirm_delete || "Are you sure you want to delete" + var err_msg_txt2 = acs_lang_text.foldercontains || "This folder contains" + // check if there is a selected file in the jsonview + var selectedRows = this.filegrid.getSelectionModel().getSelections(); + if (selectedRows.length > 0) { + // ** delete from grid ** + if (selectedRows.length == 1) { + var filetodel = selectedRows[0].get("title"); + if(selectedRows[0].get("type") === "folder") { + var msg = err_msg_txt2 + " "+selectedRows[0].get("size")+".
" + } else { + var msg = ""; + } + var msg = msg + err_msg_txt+" "+filetodel+" ?"; + } else { + var msg = err_msg_txt + ":

" + for(var x=0; x" + selectedRows[x].get("title") + " "; + if(selectedRows[x].get("type") === "folder") { + msg=msg+"("+selectedRows[x].get("size")+")"; + } + msg=msg+"
"; + } + } + this.msgbox.confirm(acs_lang_text.confirm || 'Confirm', msg, this.delFsitems,this); + } else { + // ** delete from tree ** + // we can't delete the root node + var selectednode = this.treepanel.getSelectionModel().getSelectedNode(); + var rootnode = this.treepanel.getRootNode(); + if(selectednode.attributes["id"] == rootnode.attributes["id"]) { + Ext.Msg.alert(acs_lang_text.alert || "Alert",acs_lang_text.cant_del_root || "The root folder can not be deleted."); + } else { + // return a confirmation message + this.msgbox.confirm(acs_lang_text.confirm || 'Confirm', err_msg_txt+' '+selectednode.attributes["text"]+'?', this.delFolder,this); + } + } + } + + // delete one or more folder or files + this.delFsitems = function(choice) { + + // get the rows to delete + var selectedRows = this.filegrid.getSelectionModel().getSelections(); + + // arrays for use later + var object_id = []; + + // get all node id's from json view into array + for(var x=0; x
"+response.responseText+""); + } + this.filegrid.container.unmask(); + } + + var params = "object_id="+object_id + var url = this.xmlhttpurl+"delete"; + + if (choice === "yes") { + this.filegrid.container.mask('Deleting'); + this.asyncCon.request({url:url, + params: params, + method:"POST", + callback: callback, + scope: this }); - layout.beginUpdate(); - layout.add('north', new YAHOO.ext.ContentPanel('header', '')); - layout.add('west', new YAHOO.ext.ContentPanel('folders', {title: 'Folders', fitToFrame:true, closable:false})); - innerLayout = new YAHOO.ext.BorderLayout('content', { - south: { - split:true, - initialSize: 200, - minSize: 100, - maxSize: 400, - autoScroll:true, - collapsible:true, - titlebar: true - }, - center: { - autoScroll:true + } + } + + // deletes a folder + this.delFolder = function(choice) { + + var selectednode = this.treepanel.getSelectionModel().getSelectedNode(); + var parentnode = selectednode.parentNode; + var id = selectednode.attributes["id"]; + + var callback = function(option,success,response) { + var err_msg_txt = acs_lang_text.delete_error || "Sorry, there was an error trying to delete this item." + if(success) { + if (response.responseText != "1") { + Ext.Msg.alert(acs_lang_text.error || "Error",err_msg_txt + "

"+response.responseText+""); + } else { + parentnode.fireEvent("click",parentnode); + parentnode.removeChild(selectednode); } + } else { + // delete didn't work, return error + Ext.Msg.alert(acs_lang_text.error || "Error",err_msg_txt+"

"+response.responseText+""); + } + } + + if (choice === "yes") { + this.asyncCon.request({url:this.xmlhttpurl+"delete", + params: "object_id="+id, + method:"POST", + callback: callback, + scope: this }); - innerLayout.add('south', new YAHOO.ext.ContentPanel('revisions', {title: 'Revisions', closable: false})); - innerLayout.add('south', new YAHOO.ext.ContentPanel('properties', {title: 'Properties', closable: false})); - innerLayout.add('center', new YAHOO.ext.ContentPanel('filepane')); - layout.add('center', new YAHOO.ext.NestedLayoutPanel(innerLayout)); - layout.endUpdate(); } + } -}(); -YAHOO.ext.EventManager.onDocumentReady(ajaxFsLayout.init, ajaxFsLayout, true); -/* fsList -object that manages fsItem objects*/ + // creates a new folder in the db + // inserts a blank folder in the ui ready for user to enter name + this.newFolder = function() { -function fsList() { - //properties - // array of fsItems - this.items = []; - //methods - // adds an fsItem to the array of items - this.push = function(obj) { - this.items.push(obj); + // get currently selected folder + var te = this.te; + var tree = this.treepanel; + var currentTreeNode = tree.getSelectionModel().getSelectedNode(); + currentTreeNode.expand(); + + var callback = function(option,success,response) { + var error_msg_txt = acs_lang_text.new_folder_error || "Sorry, there was an error trying to create your new folder."; + if(success) { + if (!isNaN(parseInt(response.responseText))) { + if(parseInt(response.responseText) != 0) { + // create a new blank node on the currently selected one + var newnode = currentTreeNode.appendChild(new Ext.tree.TreeNode({text:acs_lang_text.new_folder_label || 'New Folder',id:response.responseText,iconCls:'folder',singleClickExpand:true,attributes:{write_p:'t'}})); + tree.getSelectionModel().select(newnode); + newnode.loaded=true; + newnode.fireEvent("click",newnode); + setTimeout(function(){ + te.editNode = newnode; + te.startEdit(newnode.ui.textNode); + }, 10); + } else { + Ext.Msg.alert(acs_lang_text.error || "Error",error_msg_txt + "

"+response.responseText+""); + } + } + } else { + Ext.Msg.alert(acs_lang_text.error || "Error",error_msg_txt + "

"+response.responseText+""); + } + } + + this.asyncCon.request({url:this.xmlhttpurl+"newblankfolder", + params: "folder_id="+currentTreeNode.attributes["id"], + method:"POST", + callback: callback, + scope: this + }); } - // retrieves an fsItem from array given the id - this.getItem = function(id) { - var x=0; - for (x=0;x
"+response.responseText+"

"+err_msg_txt2); + node.editNode.setText(oldval); + } + } else { + // ajax failed, revert value + Ext.Msg.alert(acs_lang_text.error || "Error",err_msg_txt+":

"+response.responseText+"

"+err_msg_txt2); + node.editNode.setText(oldval); + } + } + this.asyncCon.request({url:this.xmlhttpurl+"editname", + params: "newname="+newval+"&object_id="+node.editNode.id+"&type=folder", + method:"POST", + callback: callback, + scope: this + }); + }, this, true); + + // ********** CLICK ***************** + + // assign a listener to listen for node clicks + // this will fire the proc to load the right panel + // to fetch the fs items in that folder + this.treepanel.on("click",this.loadFoldercontents,this,true) + + // ********** Grid Row DRAGDROP **************** + + // check if the file/folder can be dropped on a node + + this.treepanel.on("nodedragover",function(e){ + // DO NOT ALLOW DROP TO CURRENT FOLDER + // check if the id of target node to be dropped + // is the same as the currently selected tree node + if (e.target.id == this.treepanel.getSelectionModel().getSelectedNode().id) { + return false; + } + // DO NOT ALLOW TO DROP A NODE TO ITSELF + // check if the id of any of the nodes to be dropped + // is the same as the id on the tree + if(e.source.dragData.selections) { + for (var x=0; x
"+response.responseText+"

"+err_msg_txt2); + error = true; + } + } else { + // ajax failed, revert value + Ext.Msg.alert(acs_lang_text.error || "Error", acs_lang_text.error_and_reverted || "An error occurred. Your changes have been reverted"); + error = true; + } + // if move encountered an error, revert the change + if (error) { + option.target.removeChild(option.thenode); + option.parent.appendChild(option.thenode); + option.parent.loaded=false; + option.parent.expand(); + } else { + option.target.loaded=false; + option.target.fireEvent("click",option.target); + option.target.expand(); + } + } + + var params = "file_ids="+draggedObj+"&folder_target_id="+target; + var url = this.xmlhttpurl+"move"; + + this.asyncCon.request({url:url, + params: params, + method:"POST", + callback: callback, + scope: this, + target: t, + parent: p, + thenode: n + }); + + } else { + + // we dropped a row from the grid + var folder_target_id = ddobj.target.id; + var file_ids = []; + for(var x=0;x'; + + // Create IE Object HTML + } else { + + // Build the basic Object tag + html = ''; + html += ''; + + html += ''; + html += ''; + html += ''; + + html += ''; + } + + return html; +}; + +// This private method builds the parameter string that will be passed +// to flash. +SWFUpload.prototype.getFlashVars = function () { + // Add the cookies to the backend string + var upload_target_url = this.getSetting("upload_target_url"); + var query_string = this.buildQueryString(); + + // Build the parameter string + var html = ""; + html += "controlID=" + encodeURIComponent(this.getSetting("control_id")); + html += "&uploadTargetURL=" + encodeURIComponent(upload_target_url); + html += "&uploadQueryString=" + encodeURIComponent(query_string); + html += "&beginUploadOnQueue=" + encodeURIComponent(this.getSetting("begin_upload_on_queue")); + html += "&fileTypes=" + encodeURIComponent(this.getSetting("file_types")); + html += "&fileTypesDescription=" + encodeURIComponent(this.getSetting("file_types_description")); + html += "&fileSizeLimit=" + encodeURIComponent(this.getSetting("file_size_limit")); + html += "&fileUploadLimit=" + encodeURIComponent(this.getSetting("file_upload_limit")); + html += "&fileQueueLimit=" + encodeURIComponent(this.getSetting("file_queue_limit")); + html += "&debugEnabled=" + encodeURIComponent(this.getSetting("debug_enabled")); + + return html; +}; + +SWFUpload.prototype.buildQueryString = function () { + var upload_cookies = this.getSetting("upload_cookies"); + var upload_params = this.getSetting("upload_params"); + var query_string_pairs = []; + var i, value, name; + + // Retrieve the cookies + if (typeof(upload_cookies) === "object" && typeof(upload_cookies.length) === "number") { + for (i = 0; i < upload_cookies.length; i++) { + if (typeof(upload_cookies[i]) === "string" && upload_cookies[i] !== "") { + value = this.getCookie(upload_cookies[i]); + if (value !== "") { + query_string_pairs.push(encodeURIComponent(upload_cookies[i]) + "=" + encodeURIComponent(value)); + } + } + } + } + // Retrieve the user defined parameters + if (typeof(upload_params) === "object") { + for (name in upload_params) { + if (upload_params.hasOwnProperty(name)) { + if (typeof(upload_params[name]) === "string" /*&& upload_params[name] != ""*/) { + query_string_pairs.push(encodeURIComponent(name) + "=" + encodeURIComponent(upload_params[name])); + } + } + } + } + + return query_string_pairs.join("&"); +}; + +// This private method "loads" the UI. If a target was specified then it is assumed that "display: none" was set and +// it does a "display: block" so the UI is shown. Then if a degraded_target is specified it hides it by setting "display: none" +// If you want SWFUpload to do something else then provide a "ui_function" setting and that will be called instead. +SWFUpload.prototype.showUI = function () { + var ui_container_id, ui_target, degraded_container_id, degraded_target; + try { + ui_container_id = this.getSetting("ui_container_id"); + + if (ui_container_id !== "") { + ui_target = document.getElementById(ui_container_id); + if (ui_target !== null) { + ui_target.style.display = "block"; + + // Now that the UI has been taken care of hide the degraded UI + degraded_container_id = this.getSetting("degraded_container_id"); + if (degraded_container_id !== "") { + degraded_target = document.getElementById(degraded_container_id); + if (degraded_target !== null) { + degraded_target.style.display = "none"; + } + } + } + } + + } catch (ex) { + this.debugMessage(ex); + } +}; + +// Saves a setting. If the value given is undefined or null then the default_value is used. +SWFUpload.prototype.addSetting = function (name, value, default_value) { + if (typeof(value) === "undefined" || value === null) { + this.settings[name] = default_value; + } else { + this.settings[name] = value; + } + + return this.settings[name]; +}; + +// Gets a setting. Returns null if it wasn't found. +SWFUpload.prototype.getSetting = function (name) { + if (typeof(this.settings[name]) === "undefined") { + return ""; + } else { + return this.settings[name]; + } +}; + +// Gets a setting, if the setting is undefined then return the default value +// This does not affect or use the interal setting object. +SWFUpload.prototype.retrieveSetting = function (value, default_value) { + if (typeof(value) === "undefined" || value === null) { + return default_value; + } else { + return value; + } +}; + + +// This method is used when debugging is enabled. +// It loops through all the settings and displays +// them in the debug Console. +SWFUpload.prototype.displayDebugInfo = function () { + var key, debug_message = ""; + + debug_message += "----- DEBUG OUTPUT ----\nID: " + this.movieElement.id + "\n"; + + // It's bad to use the for..in with an associative array, but oh well + for (key in this.settings) { + if (this.settings.hasOwnProperty(key)) { + debug_message += key + ": " + this.settings[key] + "\n"; + } + } + + debug_message += "----- DEBUG OUTPUT END ----\n"; + debug_message += "\n"; + + this.debugMessage(debug_message); +}; + +// Sets the UploadTargetURL. To commit the change you must call UpdateUploadStrings. +SWFUpload.prototype.setUploadTargetURL = function (url) { + if (typeof(url) === "string") { + return this.addSetting("upload_target_url", url, ""); + } else { + return false; + } +}; +// Sets the upload_cookies array. To commit the change you must call UpdateUploadStrings. +SWFUpload.prototype.setUploadCookies = function (cookie_name_array) { + if (typeof(cookie_name_array) === "object" && typeof(cookie_name_array.length) === "number") { + return this.addSetting("upload_cookies", cookie_name_array, []); + } else { + return false; + } +}; +// Sets the upload params object. To commit the change you must call UpdateUploadStrings. +SWFUpload.prototype.setUploadParams = function (param_object) { + if (typeof(param_object) === "object") { + return this.addSetting("upload_params", param_object, []); + } else { + return false; + } +}; + +/* ***************************** + -- Flash control methods -- + Your UI should use these + to operate SWFUpload + ***************************** */ + +SWFUpload.prototype.browse = function () { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.Browse) === "function") { + try { + this.movieElement.Browse(); + } + catch (ex) { + this.debugMessage("Could not call browse: " + ex); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +// Begins the uploads (if begin_upload_on_queue is disabled) +// The file_id is optional. If specified only that file will be uploaded. If not specified SWFUpload will +// begin to process the queue. +SWFUpload.prototype.startUpload = function (file_id) { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StartUpload) === "function") { + try { + this.movieElement.StartUpload(file_id); + } + catch (ex) { + this.debugMessage("Could not call StartUpload: " + ex); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +// Cancels the current uploading item. If no item is uploading then nothing happens. +SWFUpload.prototype.cancelUpload = function (file_id) { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelUpload) === "function") { + try { + this.movieElement.CancelUpload(file_id); + } + catch (ex) { + this.debugMessage("Could not call CancelUpload"); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +// Cancels all the files in the queue. Including any current uploads. +SWFUpload.prototype.cancelQueue = function () { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.CancelQueue) === "function") { + try { + this.movieElement.CancelQueue(); + } + catch (ex) { + this.debugMessage("Could not call CancelQueue"); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +// Stops the current upload. The file is re-queued. If nothing is currently uploading then nothing happens. +SWFUpload.prototype.stopUpload = function () { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.StopUpload) === "function") { + try { + this.movieElement.StopUpload(); + } + catch (ex) { + this.debugMessage("Could not call StopUpload"); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +// Updates the upload url strings in the Flash Movie +// This must be called in order for calls to SetUploadTargetURL, SetUploadCookies, and SetUploadQueryString to take effect. +SWFUpload.prototype.updateUploadStrings = function () { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.SetUploadStrings) === "function") { + try { + this.movieElement.SetUploadStrings(this.getSetting("upload_target_url"), this.buildQueryString()); + } + catch (ex) { + this.debugMessage("Could not call SetUploadStrings"); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +SWFUpload.prototype.addFileParam = function (file_id, name, value) { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.AddFileParam) === "function") { + try { + return this.movieElement.AddFileParam(file_id, encodeURIComponent(name), encodeURIComponent(value)); + } + catch (ex) { + this.debugMessage("Could not call addFileParam"); + } + } else { + this.debugMessage("Could not find Flash element"); + } +}; + +SWFUpload.prototype.removeFileParam = function (file_id, name) { + if (typeof(this.movieElement) !== "undefined" && typeof(this.movieElement.RemoveFileParam) === "function") { + try { + return this.movieElement.RemoveFileParam(file_id, encodeURIComponent(name)); + } + catch (ex) { + this.debugMessage("Could not call addFileParam"); + } + } else { + this.debugMessage("Could not find Flash element"); + } + +}; + +/* ******************************* + Default Event Handlers +******************************* */ +// This is the callback method that the Flash movie will call when it has been loaded and is ready to go. +// Calling this or showUI "manually" bypass the Flash Detection built in to SWFUpload. +// FlashReady should not generally be overwritten. Use a ui_function setting if you want to control the UI loading after the flash has loaded. +SWFUpload.prototype.flashReady = function () { + var ui_function; + try { + this.debugMessage("Flash called back and is ready."); + + ui_function = this.getSetting("ui_function"); + if (typeof(ui_function) === "function") { + ui_function.apply(this); + } else { + this.showUI(); + } + } catch (ex) { + this.debugMessage(ex); + } +}; + +// Called when the user cancels the File browser window. +SWFUpload.prototype.dialogCancelled = function () { + this.debugMessage("browse Dialog Cancelled."); +}; + +// Called once for file the user selects +SWFUpload.prototype.fileQueued = function (file) { + this.debugMessage("File Queued: " + file.id); +}; + +// Called during upload as the file progresses +SWFUpload.prototype.fileProgress = function (file, bytes_complete) { + this.debugMessage("File Progress: " + file.id + ", Bytes: " + bytes_complete); +}; + +// Called after a file is cancelled +SWFUpload.prototype.fileCancelled = function (file) { + this.debugMessage("File Cancelled: " + file.id); +}; + +// Called when a file upload has completed +SWFUpload.prototype.fileComplete = function (file) { + this.debugMessage("File Complete: " + file.id); +}; + +// Called when at least 1 file has been uploaded and there are no files remaining in the queue. +SWFUpload.prototype.queueComplete = function (file_upload_count) { + this.debugMessage("Queue Complete. Files Uploaded:" + file_upload_count); +}; + +// Called when the upload is stopped. +SWFUpload.prototype.queueStopped = function (file) { + this.debugMessage("Queue Stopped. File Stopped:" + file.id); +}; + +// Called by SWFUpload JavaScript and Flash flash functions when debug is enabled +SWFUpload.prototype.debug = function (message) { + this.debugMessage(message); +}; + +// Called when an error occurs. Use errcode to determine which error occurred. +SWFUpload.prototype.error = function (errcode, file, msg) { + try { + switch (errcode) { + case SWFUpload.ERROR_CODE_HTTP_ERROR: + this.debugMessage("Error Code: HTTP Error, File name: " + file.name + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_MISSING_UPLOAD_TARGET: + this.debugMessage("Error Code: No backend file, File name: " + file.name + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_IO_ERROR: + this.debugMessage("Error Code: IO Error, File name: " + file.name + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_SECURITY_ERROR: + this.debugMessage("Error Code: Security Error, File name: " + file.name + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_FILE_EXCEEDS_SIZE_LIMIT: + this.debugMessage("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_ZERO_BYTE_FILE: + this.debugMessage("Error Code: Zero Byte File, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_UPLOAD_LIMIT_EXCEEDED: + this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_QUEUE_LIMIT_EXCEEDED: + this.debugMessage("Error Code: Upload limit reached, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_UPLOAD_FAILED: + this.debugMessage("Error Code: Upload Initialization exception, File name: " + file.name + ", File size: " + file.size + ", Message: " + msg); + break; + case SWFUpload.ERROR_CODE_SPECIFIED_FILE_NOT_FOUND: + this.debugMessage("Error Code: File ID specified for upload was not found, Message: " + msg); + break; + default: + this.debugMessage("Error Code: Unhandled error occured. Errorcode: " + errcode); + } + } catch (ex) { + this.debugMessage(ex); + } +}; + +/* ********************************** + Utility Functions + ********************************** */ +// Gets a cookie (http://www.w3schools.com/js/js_cookies.asp) +SWFUpload.prototype.getCookie = function (cookie_name) { + var cookie_start, cookie_end; + try { + if (document.cookie.length > 0 && cookie_name !== "") + { + cookie_start = document.cookie.indexOf(cookie_name + "="); + if (cookie_start !== -1) + { + cookie_start = cookie_start + cookie_name.length + 1; + cookie_end = document.cookie.indexOf(";", cookie_start); + if (cookie_end === -1) { + cookie_end = document.cookie.length; + } + + return unescape(document.cookie.substring(cookie_start, cookie_end)); + } + } + } catch (ex) { + this.debugMessage(ex); + } + + return ""; +}; + +/* ********************************** + Debug Console + The debug console is a self contained, in page location + for debug message to be sent. The Debug Console adds + itself to the body if necessary. + + The console is automatically scrolled as messages appear. + ********************************** */ +SWFUpload.prototype.debugMessage = function (message) { + var exception_message, exception_values; + + if (this.debug_enabled) { + if (typeof(message) === "object" && typeof(message.name) === "string" && typeof(message.message) === "string") { + exception_message = ""; + exception_values = []; + for (var key in message) { + exception_values.push(key + ": " + message[key]); + } + exception_message = exception_values.join("\n"); + exception_values = exception_message.split("\n"); + exception_message = "EXCEPTION: " + exception_values.join("\nEXCEPTION: "); + SWFUpload.Console.writeLine(exception_message); + } else { + SWFUpload.Console.writeLine(message); + } + } +}; + +SWFUpload.Console = {}; +SWFUpload.Console.writeLine = function (message) { + var console, documentForm; + + try { + console = document.getElementById("SWFUpload_Console"); + + if (!console) { + documentForm = document.createElement("form"); + document.getElementsByTagName("body")[0].appendChild(documentForm); + + console = document.createElement("textarea"); + console.id = "SWFUpload_Console"; + console.style.fontFamily = "monospace"; + console.setAttribute("wrap", "off"); + console.wrap = "off"; + console.style.overflow = "auto"; + console.style.width = "700px"; + console.style.height = "350px"; + console.style.margin = "5px"; + documentForm.appendChild(console); + } + + console.value += message + "\n"; + + console.scrollTop = console.scrollHeight - console.clientHeight; + } catch (ex) { + alert("Exception: " + ex.name + " Message: " + ex.message); + } +}; Index: openacs-4/packages/ajax-filestorage-ui/www/resources/swfupload/swfupload.swf =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/resources/swfupload/swfupload.swf,v diff -u Binary files differ Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/delete.adp,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.adp 6 Nov 2006 13:15:58 -0000 1.1 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.adp 8 Sep 2007 14:32:56 -0000 1.2 @@ -1,2 +1 @@ -showstatus("@message;noquote@","@error@"); -@action;noquote@ \ No newline at end of file +@result;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/delete.tcl,v diff -u -r1.1 -r1.2 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl 6 Nov 2006 13:15:58 -0000 1.1 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/delete.tcl 8 Sep 2007 14:32:56 -0000 1.2 @@ -1,48 +1,49 @@ ad_page_contract { - Delete a file from a folder. This page is called via XMLHTTP. - The xmlhttp call should pass the id of the element dropped to the trash icon. - This dropped element should have the file_id to be deleted. + Delete an fs item. @author Hamilton Chua (ham@solutiongrove.com) - + @creation-date 2007-06-03 + } { - file_element + object_id } -set fs_object_id [string range $file_element 4 [string length $file_element]] +set user_id [ad_conn user_id] + +set result 1 +set fs_object_ids [split $object_id ","] set viewing_user_id [ad_conn user_id] -# ns_log Notice "HAM : fs_object_id : $fs_object_id" +db_transaction { -set action "" -set error 0 + foreach fs_object_id $fs_object_ids { -if { ![fs::object_p -object_id $fs_object_id] || [fs::folder_p -object_id $fs_object_id]} { - set message "Sorry, this object is not a File Storage Object. Delete Failed." - set error 1 -} else { - # DEDS: for export - set fs_package_id [lindex [fs::get_folder_package_and_root $fs_object_id] 0] - # check if user has permission to delete the file - if { [permission::permission_p -party_id $viewing_user_id -object_id $fs_object_id -privilege "delete"] } { - set message "Success !! File has been deleted." - set action "\$('row_${fs_object_id}').style.display='none';" - - db_transaction { - db_exec_plsql file_delete "select file_storage__delete_file(:fs_object_id);" - # fs::delete_file -item_id $fs_object_id -parent_id [fs::get_parent -item_id $fs_object_id] - } on_error { - set message "Delete Failed." - set action "" - set error 1 - } - } else { - set message "You do not have permission to delete this file." - set error 1 - } -} + if { ![fs::object_p -object_id $fs_object_id]} { + set result "Sorry, this object is not a File Storage Object." + db_abort_transaction + break; + } else { + # check if user has permission to delete the file/folder + if { [permission::permission_p -party_id $viewing_user_id -object_id $fs_object_id -privilege "delete"] } { + if { [fs::folder_p -object_id $fs_object_id] } { + fs::delete_folder -folder_id $fs_object_id -parent_id [fs::get_parent -item_id $fs_object_id] + } else { + fs::delete_file -item_id $fs_object_id + } + } else { + set result "You do not have permission to delete this file." + db_abort_transaction + break; + } + } -if {[info exists fs_package_id]} { - fs::export::export_one_instance -package_id $fs_package_id + } + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + } + Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/editname.adp,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.adp 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.adp 8 Sep 2007 14:32:56 -0000 1.3 @@ -1 +1 @@ -@newname;noquote@ \ No newline at end of file +@result;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/editname.tcl,v diff -u -r1.2 -r1.3 --- openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl 25 Dec 2006 16:23:26 -0000 1.2 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/editname.tcl 8 Sep 2007 14:32:56 -0000 1.3 @@ -1,21 +1,47 @@ ad_page_contract { - Accepts the object_id and changes it to newname + Accepts the object_id and a new name for the object. + Returns 1 if update is successful, should return an error message if not. - @author Hamilton Chua (ham@solutiongrove.com) - @creation-date May 7, 2006 + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-05-07 } { - newname - object_id + newname + object_id type + url:optional } +set user_id [ad_conn user_id] + +# check permissions on parent folder +# see if the user has write +if { ![permission::permission_p -no_cache \ + -party_id $user_id \ + -object_id $object_id \ + -privilege "write"] } { + + ns_return 500 "text/html" "You do not have permission to rename." + ad_script_abort +} + +set result 1 + # change the name of the give object_id if { [exists_and_not_null newname] } { # determine if this is a folder or file - if { $type == "folder" } { - db_dml "rename_folder" "update cr_folders set label = :newname where folder_id = :object_id" - } else { - db_dml "rename_file" "update cr_revisions set title=:newname where revision_id=(select live_revision from cr_items where item_id=:object_id)" + db_transaction { + if { $type == "folder" } { + fs::rename_folder -folder_id $object_id -name $newname + } elseif { $type == "url" } { + content_extlink::edit -extlink_id $object_id -url $url -label $newname -description "" + } else { + set title $newname + set file_id $object_id + db_dml dbqd.file-storage.www.file-edit-2.edit_title {} + } + } on_error { + ns_return 500 "text/html" $errmsg + ad_script_abort } } \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add-flash.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/file-add-flash.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add-flash.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,125 @@ +ad_page_contract { + + script to recieve the new file and insert it into the database + +} { + Filedata:trim,notnull + Filedata.tmpfile:tmpfile +} + +set query [ns_conn query] +set query_set [ns_parsequery $query] + +set folder_id [ns_set get $query_set "folder_id"] +if ![fs_folder_p $folder_id] { + ns_return 500 "text/html" "[_ file-storage.lt_The_specified_parent_]" + ad_script_abort +} + +set package_id [ns_set get $query_set "package_id"] +set user_id [ns_set get $query_set "user_id"] +set filetitle [ns_set get $query_set "filetitle"] +set filedescription [ns_set get $query_set "filedescription"] +set unpack_p [ns_set get $query_set "unpack_p"] + +# ns_log notice "HAM : UPLOADING FILE : $folder_id : $Filedata : $Filedata.tmpfile : $package_id : $user_id***" + +# Get the ip +set creation_ip [ad_conn peeraddr] + +set action "" + +set result "" + +# Check for write permission on this folder +# ad_require_permission $folder_id write +if { ![permission::permission_p -object_id $folder_id -privilege "write" -party_id $user_id] } { + # ns_log notice "HAM : You don't have permission to add files to this folder" + ns_return 500 "text/html" "You don't have permission to add files to this folder." + ad_script_abort +} + +# Get the storage type +set indb_p [parameter::get -package_id $package_id -parameter StoreFilesInDatabaseP] + +set unpack_p [template::util::is_true $unpack_p] + +set unzip_binary [string trim [parameter::get -package_id $package_id -parameter UnzipBinary]] + +if { $unpack_p && ![empty_string_p $unzip_binary] && [file extension [template::util::file::get_property filename $Filedata]] eq ".zip" } { + + set path [ns_tmpnam] + file mkdir $path + + + catch { exec $unzip_binary -jd $path ${Filedata.tmpfile} } errmsg + + # More flexible parameter design could be: + # zip {unzip -jd {out_path} {in_file}} tar {tar xf {in_file} {out_path}} tgz {tar xzf {in_file} {out_path}} + + set upload_files [list] + set upload_tmpfiles [list] + + foreach file [glob -nocomplain "$path/*"] { + lappend upload_files [file tail $file] + lappend upload_tmpfiles $file + } + +} else { + set upload_files [list $Filedata] + set upload_tmpfiles [list ${Filedata.tmpfile}] +} + +db_transaction { + + foreach upload_file $upload_files tmpfile $upload_tmpfiles { + + set mime_type [cr_filename_to_mime_type -create $upload_file] + + # Get the filename part of the upload file + if { ![regexp {[^//\\]+$} $upload_file filename] } { + # no match + set filename $upload_file + } + + # Get the title + if { [empty_string_p $filetitle] || $unpack_p } { + set filetitle $filename + } + + set file_id [db_nextval "acs_object_id_seq"] + fs::add_file \ + -name $filename \ + -item_id $file_id \ + -parent_id $folder_id \ + -tmp_filename $tmpfile\ + -creation_user $user_id \ + -creation_ip $creation_ip \ + -title $filetitle \ + -description "" \ + -package_id $package_id \ + -mime_type $mime_type + + file delete $tmpfile + + # We know the user has write permission to this folder, but they may not have admin privileges. + # They should always be able to admin their own file by default, so they can delete it, control + # who can read it, etc. + + if { [string is false [permission::permission_p -party_id $user_id -object_id $folder_id -privilege admin]] } { + permission::grant -party_id $user_id -object_id $file_id -privilege admin + } + + # So we'll set the title from the filename in the next iteration + set filetitle {} + } + + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + +} + +ad_return_template "file-add" Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/file-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +@result;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/file-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/file-add.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,130 @@ +ad_page_contract { + + script to recieve the new file and insert it into the database + +} { + folder_id:integer,notnull + upload_file:notnull,trim + upload_file.tmpfile:tmpfile + package_id:integer,notnull + {filetitle:trim ""} + filedescription + {unpack_p:boolean "f"} +} -validate { + valid_folder -requires {folder_id:integer} { + if ![fs_folder_p $folder_id] { + ns_return 500 "text/html" "[_ file-storage.lt_The_specified_parent_]" + ad_script_abort + } + } + max_size -requires {upload_file} { + set n_bytes [file size ${upload_file.tmpfile}] + set max_bytes [parameter::get -package_id $package_id -parameter "MaximumFileSize"] + # ns_log notice "HAM : $n_bytes : $max_bytes *" + if { $n_bytes > $max_bytes } { + ns_return 500 "text/html" [_ file-storage.lt_Your_file_is_larger_t_1 [list max_number_of_bytes [util_commify_number $max_bytes]]] + ad_script_abort + } + } +} + +# ns_log notice "HAM : UPLOADING FILE : $folder_id : $upload_file : $upload_file.tmpfile ***" + +# Get the user +set user_id [auth::require_login] + +# Get the ip +set creation_ip [ad_conn peeraddr] + +set action "" + +set result "" + +# Check for write permission on this folder +# ad_require_permission $folder_id write +if { ![permission::permission_p -object_id $folder_id -privilege "write"] } { + ns_return 500 "text/html" "You don't have permission to add files to this folder." + ad_script_abort +} + +# Get the storage type +set indb_p [parameter::get -package_id $package_id -parameter StoreFilesInDatabaseP] + +set unpack_p [template::util::is_true $unpack_p] +set unzip_binary [string trim [parameter::get -package_id $package_id -parameter UnzipBinary]] + +if { $unpack_p && ![empty_string_p $unzip_binary] && [file extension [template::util::file::get_property filename $upload_file]] eq ".zip" } { + + set path [ns_tmpnam] + file mkdir $path + + + catch { exec $unzip_binary -jd $path ${upload_file.tmpfile} } errmsg + + # More flexible parameter design could be: + # zip {unzip -jd {out_path} {in_file}} tar {tar xf {in_file} {out_path}} tgz {tar xzf {in_file} {out_path}} + + set upload_files [list] + set upload_tmpfiles [list] + + foreach file [glob -nocomplain "$path/*"] { + lappend upload_files [file tail $file] + lappend upload_tmpfiles $file + } + +} else { + set upload_files [list $upload_file] + set upload_tmpfiles [list ${upload_file.tmpfile}] +} + +db_transaction { + + foreach upload_file $upload_files tmpfile $upload_tmpfiles { + + set mime_type [cr_filename_to_mime_type -create $upload_file] + + # Get the filename part of the upload file + if { ![regexp {[^//\\]+$} $upload_file filename] } { + # no match + set filename $upload_file + } + + # Get the title + if { [empty_string_p $filetitle] || $unpack_p } { + set filetitle $filename + } + + set file_id [db_nextval "acs_object_id_seq"] + fs::add_file \ + -name $filename \ + -item_id $file_id \ + -parent_id $folder_id \ + -tmp_filename $tmpfile\ + -creation_user $user_id \ + -creation_ip $creation_ip \ + -title $filetitle \ + -description "" \ + -package_id $package_id \ + -mime_type $mime_type + + file delete $tmpfile + + # We know the user has write permission to this folder, but they may not have admin privileges. + # They should always be able to admin their own file by default, so they can delete it, control + # who can read it, etc. + + if { [string is false [permission::permission_p -party_id $user_id -object_id $folder_id -privilege admin]] } { + permission::grant -party_id $user_id -object_id $file_id -privilege admin + } + + # So we'll set the title from the filename in the next iteration + set filetitle {} + } + + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + +} Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/foldercontents.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/foldercontents.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/foldercontents.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,5 @@ +{ "total": @counter@, "foldercontents":[ + +{"id":"@contents.object_id@","icon":"@contents.icon;noquote@","type":"@contents.type;noquote@",title_and_name:"@contents.title;noquote@
@contents.filename;noquote@","title":"@contents.title;noquote@","filename":"@contents.filename;noquote@","url":"@contents.download_url;noquote@","size":"@contents.content_size_pretty@","lastmodified":"@contents.last_modified_pretty@","write_p":@contents.write_p@} +
+]} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/foldercontents.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/foldercontents.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/foldercontents.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,113 @@ +ad_page_contract { + + Given the folder_id, this page will return JSON with + data of the contents of that folder + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-06-03 + +} { + folder_id:integer,notnull + {sort "fs_objects.title"} + {dir "DESC"} +} + +# who's looking +set viewing_user_id [ad_conn user_id] + +# find out which file storage instance we are at +# so that we can get a path to prefix to the files + +set root_package_id [ajaxfs::get_root_folder -folder_id $folder_id] +set fs_url [apm_package_url_from_id $root_package_id] + +set folder_name [lang::util::localize [fs::get_object_name -object_id $folder_id]] +set folder_path "" + +if {![exists_and_not_null fs_url]} { set fs_url "" } +if {![exists_and_not_null root_folder_id]} { set root_folder_id [fs::get_root_folder -package_id $root_package_id] } + +if {![string equal $root_folder_id $folder_id]} { + set folder_path [db_exec_plsql dbqd.file-storage.www.folder-chunk.get_folder_path {}] +} else { + set folder_path "" +} + +set content_size_total 0 +set counter 0 +set n_past_days 99999 + +# sorting ********** +set orderby "" +if { [exists_and_not_null sort] } { + if {$sort == "title_and_name"} { set sort "fs_objects.title" } + if {$sort == "size"} { set sort "fs_objects.content_size" } + if {$sort == "lastmodified"} { set sort "fs_objects.last_modified" } + set orderby "order by $sort $dir" +} + +db_multirow -extend { filename icon last_modified_pretty content_size_pretty download_url object_counter file_list_start file_list_end write_p} contents dbqd.file-storage.www.folder-chunk.select_folder_contents { } { + + if { ![exists_and_not_null title] } { set title $name } + + # content size + if {[string equal $type "folder"]} { + set content_size_pretty [lc_numeric $content_size] + append content_size_pretty " [_ file-storage.items]" + set pretty_type "Folder" + } else { + if {$content_size < 1024} { + set content_size_pretty "[lc_numeric $content_size] [_ file-storage.bytes]" + } else { + set content_size_pretty "[lc_numeric [expr $content_size / 1024 ]] [_ file-storage.kb]" + } + } + + set last_modified_pretty [lc_time_fmt $last_modified_ansi "%x %X"] + + # icon + switch -- $type { + folder { + set icon "" + } + url { + set icon "" + set download_url $url + set content_size_pretty "" + } + "application/pdf" { + set icon "" + } + "application/vnd.ms-excel" { + set icon "" + } + "application/zip" { + set icon "" + } + "application/msword" { + set icon "" + } + "video/x-flv" { + set icon "" + } + default { + set icon "" + } + } + + if { $type != "folder"} { + if { ![exists_and_not_null download_url] } { + set download_url "${fs_url}download/${name}?[export_vars {{file_id $object_id}}]" + } + set filename $name + if { $title == $name } { set filename " "} + } else { + set download_url "javascript:void(0)" + set filename " " + } + + if { [permission::permission_p -party_id $viewing_user_id -object_id $object_id -privilege "write"] == "t" } { set write_p "true" } else { set write_p "false" } + + incr counter + +} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/getrootfolder.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/getrootfolder.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/getrootfolder.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +{text:"@name;noquote@@title;noquote@", id:"@object_id@","attributes":{"write_p":"@write_p@"}} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/getrootfolder.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/getrootfolder.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/getrootfolder.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,27 @@ +ad_page_contract { + + Given the package_id, this page will return JSON with + the details of the root folder + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-06-03 + +} { + package_id:integer,notnull + root_folder_id:integer,optional +} + +if { [exists_and_not_null root_folder_id] } { + set rootfolder $root_folder_id +} else { + set rootfolder [fs::get_root_folder -package_id $package_id] +} + +set write_p [permission::permission_p -no_cache \ + -party_id [ad_conn user_id] \ + -object_id ${rootfolder} \ + -privilege "write"] + +if { $write_p } { set write_p "t" } else { set write_p "f" } + +db_0or1row "getfolderinfo" "select * from fs_objects where object_id = :rootfolder" \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes-oracle.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/loadnodes-oracle.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes-oracle.xql 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + + oracle + 8.1.6 + + + + + select fs_objects.object_id, fs_objects.name, fs_objects.title, fs_objects.parent_id, + case + when fs_objects.type = 'url' + then ( select acs_permission.permission_p(fs_objects.object_id, :viewing_user_id, 'write') from dual) + else 't' + end as write_p + from fs_objects + where fs_objects.type='folder' + and fs_objects.parent_id = :node + and exists (select 1 + from acs_object_party_privilege_map m + where m.object_id = fs_objects.object_id + and m.party_id = :viewing_user_id + and m.privilege = 'read') order by fs_objects.title + + + + \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes-postgresql.xql =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/loadnodes-postgresql.xql,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes-postgresql.xql 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,31 @@ + + + + + + + postgresql + 7.2 + + + + + select fs_objects.object_id, fs_objects.name, fs_objects.title, fs_objects.parent_id, + case + when fs_objects.type = 'url' + then ( select acs_permission__permission_p(fs_objects.object_id, :viewing_user_id, 'write') from dual) + else 't' + end as write_p + from fs_objects + where fs_objects.type='folder' + and fs_objects.parent_id = :node + and exists (select 1 + from acs_object_party_privilege_map m + where m.object_id = fs_objects.object_id + and m.party_id = :viewing_user_id + and m.privilege = 'read') order by fs_objects.title + + + + \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/loadnodes.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +[{"text":"@treenodes.name@","id":"@treenodes.id;noquote@","iconCls":'folder',"singleClickExpand":true,"attributes":{"write_p":"@treenodes.write_p@"}}] \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/loadnodes.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/loadnodes.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,33 @@ +ad_page_contract { + + Returns a JSON structure suitable for building the nodes of a tree + for the ajax file storage ui. + Requires the package_id + + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-06-03 + +} { + package_id:integer,notnull + {node ""} +} + +# ns_log notice "ln called with package_id '$package_id' and node '$node'" + +set viewing_user_id [ad_conn user_id] + +if { ![exists_and_not_null node] } { + # if node is empty, then get the rootfolder of the package_id + set node [fs::get_root_folder -package_id $package_id] +} + +db_multirow -extend { text id href cls } "treenodes" "treenodes" { } { + if { [exists_and_not_null title] } { + set text $title + } else { + set text $name + } + set id "$object_id" + set cls "folder" +} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/move.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/move.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/move.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +@results;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/move.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/move.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/move.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,44 @@ +ad_page_contract { + + Allow an fs_item where file or folder to be moved to + a new target folder. + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-06-03 + +} { + folder_target_id:integer,notnull + file_ids +} + +set user_id [ad_conn user_id] + +# check permissions on parent folder +# see if the user has write +set parent_id [fs::get_parent -item_id $folder_target_id] +if { ![permission::permission_p -no_cache \ + -party_id $user_id \ + -object_id $parent_id \ + -privilege "write"] } { + + ns_return 500 "text/html" "You do not have permission to create a folder" + ad_script_abort +} + +set results 1 +set file_id_list [split $file_ids ","] + +db_transaction { + + foreach file_id $file_id_list { + set parent_id $folder_target_id + set address [ad_conn peeraddr] + db_exec_plsql dbqd.file-storage.www.file-move-2.file_move {} + } + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + +} \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/newblankfolder.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/newblankfolder.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/newblankfolder.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +@result;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/newblankfolder.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/newblankfolder.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/newblankfolder.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,56 @@ +ad_page_contract { + + Creates a new folder in the given folder_id + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2007-03-13 +} { + {folder_id:integer,notnull} +} + +# make sure user is logged in +set user_id [ad_conn user_id] + +# is this the root folder +set fslistinfo [fs::get_folder_package_and_root $folder_id] +if { $folder_id == [lindex $fslistinfo 1] } { + set parent_id $folder_id +} else { + # check permissions on parent folder + # see if the user has write + set parent_id [fs::get_parent -item_id $folder_id] +} + +if { ![permission::permission_p -no_cache \ + -party_id $user_id \ + -object_id $parent_id \ + -privilege "write"] } { + + ns_return 500 "text/html" "You do not have permission to create a folder" + ad_script_abort +} + + +set result 0 +set folder_name "New Folder" +set description "" + +db_transaction { + + set new_folder_id [fs::new_folder \ + -name [ns_rand] \ + -pretty_name $folder_name \ + -parent_id $folder_id \ + -creation_user $user_id \ + -creation_ip [ad_conn peeraddr] \ + -description $description] + + set result $new_folder_id + +} on_error { + + ns_return 500 "text/html" $errmsg + ad_script_abort + +} + Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/sort-files.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/sort-files.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/sort-files.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,19 @@ +ad_page_contract { + Accepts key value pairs and reorganizes files accordingly +} { + object_ids:integer,multiple +} + +if { [exists_and_not_null object_ids] } { + set order_n 1 + foreach x $object_ids { + if { [db_0or1row "exists" "select item_id from fs_objects_extension where item_id=:x"] } { + db_dml "sort_portlet" "update fs_objects_extension set order_n=:order_n where item_id=:x" + } else { + db_dml "insert_sort_portlet" "insert into fs_objects_extension (item_id,order_n) values (:x,:order_n)" + } + incr order_n + } +} + +ns_return 200 "text/html" "ok" \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/url-add.adp =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/url-add.adp,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/url-add.adp 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1 @@ +@result;noquote@ \ No newline at end of file Index: openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/url-add.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/Attic/url-add.tcl,v diff -u --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ openacs-4/packages/ajax-filestorage-ui/www/xmlhttp/url-add.tcl 8 Sep 2007 14:32:56 -0000 1.1 @@ -0,0 +1,34 @@ +ad_page_contract { + +Add a URL to the file storage instance + +} { + folder_id:integer,notnull + package_id:integer,notnull + fstitle:notnull,trim + fsdescription + fsurl:notnull,trim +} + +set user_id [ad_conn user_id] +set result "OK" + +# Check for write permission on this folder +# ad_require_permission $folder_id write +if { ![permission::permission_p -object_id $folder_id -privilege "write"] } { + ns_return 500 "text/html" "You don't have permission to create a url on this folder." + ad_script_abort +} + +set item_id [content_extlink::new -url $fsurl -label $fstitle -description $fsdescription -parent_id $folder_id] + +# Analogous as for files (see file-add-2) we know the user has write permission to this folder, +# but they may not have admin privileges. +# They should always be able to admin their own url (item) by default, so they can delete it, control +# who can read it, etc. + +if { [string is false [permission::permission_p -party_id $user_id -object_id $folder_id -privilege admin]] } { + permission::grant -party_id $user_id -object_id $item_id -privilege admin +} + +fs::do_notifications -folder_id $folder_id -filename $fsurl -item_id $item_id -action "new_url"