Author Topic: Mod: column filesize in list view  (Read 4184 times)

Henry

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Mod: column filesize in list view
« on: December 30, 2010, 06:26:21 pm »
Hi,
i created a mod that added the column size in the documents list view.


created with FO version: 1.7.3.1

Have fun.

Henry

« Last Edit: December 31, 2010, 10:53:51 am by Henry »

Robert1724

  • Jr. Member
  • **
  • Posts: 72
    • View Profile
Re: Mod: column filesize in list view
« Reply #1 on: January 01, 2011, 12:44:57 pm »
Hi:

Can you describe how to turn modify the code to display the size of documents ?

Henry

  • Full Member
  • ***
  • Posts: 159
    • View Profile
Re: Mod: column filesize in list view
« Reply #2 on: January 01, 2011, 03:56:44 pm »
you change the code of this two files.

\public\assets\javascript\og\FileManager.js
\public\assets\javascript\og\og.js

the file "FileManager.js" contains the code to generate the documents list.

line 11 define the fields or attributes of the files.
the field list must extend with the attribute "size".
Code: [Select]
this.fields =
['name', 'object_id', 'type', 'tags', 'createdBy', 'createdById',
 ...
'isMP3','size'];

Now we need a render function. This function generate the formated size information. I have create the function between the other render functions.

Code: [Select]
function renderSize(value, p, r) {
if (!value) {
return "";
}
return userString = String.format('{0}',og.filesizeFormat(r.data.size));

}

The 3. step is necessary to create the new column in the document list.
at the end (after action) of the column declarations you can add the new size column.
Code: [Select]
},{
id: 'actions',
header: lang("actions"),
width: 50,
renderer: renderActions,
sortable: false
},{
id: 'size',
header: lang("size"),
dataIndex: 'size',
width: 50,   
renderer: renderSize,    // call the renderSize function
sortable: true           // i don't no why, but this column is not sortable
        }]);


This are all changes in the FileManager.js
Now it works but  the size is showing like 2.2.6 MB.

To change this you must change the og.filesizeFormat function in  og.js file.

Code: [Select]
/* original entry
og.filesizeFormat = function(fs) {
if (fs > 1024 * 1024) {
var total = Math.round(fs / 1024 / 1024 * 10);
return total / 10 + "." + total % 10 + " MB";
} else {
var total = Math.round(fs / 1024 * 10);
return total / 10 + "." + total % 10 + " KB";
}
};
*/
// new function to calulate the filesize
og.filesizeFormat = function(fs) {
var units = new Array(' B',' KiB',' MiB',' GiB',' TiB'); // More informations http://en.wikipedia.org/wiki/Byte
var i = 0;
while (i<units.length && fs > 1024){
fs = fs / 1024;
i++;
}
if (i!=0){
fs = Math.round(fs * 100)/100;
}
return fs + units[i];
};

My english is terrible but i hope you can understand me.




franponce87

  • Administrator
  • Hero Member
  • *****
  • Posts: 1819
    • View Profile
    • Email
Re: Mod: column filesize in list view
« Reply #3 on: January 03, 2011, 08:56:37 am »
Once again, thanks for the contribution Henry!
Your English is more than great, so do not worry about it!


Keep up the good work!

Best regards,
Francisco
Would you like to install Feng Office Professional or Enterprise Edition in your servers? No problem! Read this article!

filriyadh

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Mod: column filesize in list view
« Reply #4 on: January 11, 2011, 10:47:06 am »
nice write up. Thanks

 

anything
anything