blob: b727c6c2d7169f003c6c2cc20cdb673791f6abe6 [file] [log] [blame]
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -08001function number_format(number, decimals, dec_point, thousands_sep)
2{
3 // http://kevin.vanzonneveld.net
4 // + original by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
5 // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
6 // + bugfix by: Michael White (http://crestidg.com)
7 // + bugfix by: Benjamin Lupton
8 // + bugfix by: Allan Jensen (http://www.winternet.no)
9 // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
10 // * example 1: number_format(1234.5678, 2, '.', '');
11 // * returns 1: 1234.57
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080012
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080013 var n = number, c = isNaN(decimals = Math.abs(decimals)) ? 2 : decimals;
14 var d = dec_point == undefined ? "," : dec_point;
15 var t = thousands_sep == undefined ? "." : thousands_sep, s = n < 0 ? "-" : "";
16 var i = parseInt(n = Math.abs(+n || 0).toFixed(c)) + "",
17 j = (j = i.length) > 3 ? j % 3 : 0;
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080018
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080019 return s + (j ? i.substr(0, j) + t : "") +
20 i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t) +
21 (c ? d + Math.abs(n - i).toFixed(c).slice(2) : "");
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080022}
23
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080024function SegNumToFileSize(segNum)
25{
26 filesize = segNum * 1024;
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080027
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080028 if (filesize >= 1073741824) {
29 filesize = number_format(filesize / 1073741824, 2, '.', '') + ' Gb';
30 }
31 else {
32 if (filesize >= 1048576) {
33 filesize = number_format(filesize / 1048576, 2, '.', '') + ' Mb';
34 }
35 else {
36 if (filesize > 1024) {
37 filesize = number_format(filesize / 1024, 0) + ' Kb';
38 }
39 else {
40 filesize = '< 1 Kb';
41 };
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080042 };
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080043 };
44 return filesize;
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080045};
46
47/**
48 * @brief Convert binary data represented as non-escaped hex string to Uint8Array
49 * @param str String like ba0cb43e4b9639c114a0487d5faa7c70452533963fc8beb37d1b67c09a48a21d
50 *
51 * Note that if string length is odd, null will be returned
52 */
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080053StringHashToUint8Array = function(str) {
54 if (str.length % 2 != 0) {
55 return null;
56 }
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080057
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080058 var buf = new Uint8Array(str.length / 2);
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080059
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080060 for (var i = 0; i < str.length; i += 2) {
61 value = parseInt(str.substring(i, i + 2), 16);
62 buf[i / 2] = value;
63 }
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080064
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080065 return buf;
Alexander Afanasyev3c95c852013-03-01 18:58:50 -080066};
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -080067
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080068imgFullPath =
69 function(imgName) {
70 return "images/" + imgName + ".png";
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -080071}
72
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080073fileExtension = function(fileName) {
74 defaultExtension = "file";
75 knownExtensions = [
76 "ai", "aiff", "bib", "bz2", "c", "chm", "conf", "cpp", "css", "csv",
77 "deb", "divx", "doc", "file", "gif", "gz", "hlp", "htm", "html", "iso",
78 "jpeg", "jpg", "js", "mov", "mp3", "mpg", "odc", "odf", "odg", "odi",
79 "odp", "ods", "odt", "ogg", "pdf", "pgp", "php", "pl", "png", "ppt",
80 "pptx", "ps", "py", "ram", "rar", "rb", "rm", "rpm", "rtf", "sql",
81 "swf", "sxc", "sxd", "sxi", "sxw", "tar", "tex", "tgz", "txt", "vcf",
82 "wav", "wma", "wmv", "xls", "xml", "xpi", "xvid", "zip"
83 ];
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -080084
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080085 extStart = fileName.lastIndexOf('.');
86 if (extStart < 0) {
87 return imgFullPath(defaultExtension);
88 }
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -080089
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -080090 extension = fileName.substr(extStart + 1);
91 // return imgFullPath (extension);
92 if ($.inArray(extension, knownExtensions) >= 0) {
93 return extension;
94 }
95 else {
96 return defaultExtension;
97 }
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -080098};
99
100
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800101openHistoryForItem = function(fileName) {
Alexander Afanasyeve16ed212016-12-25 18:09:44 -0800102 url = new HistoryDisplay(null).base_no_item_url("fileHistory")
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800103 url += "&item=" + encodeURIComponent(encodeURIComponent(fileName));
104 document.location = url;
Alexander Afanasyevf7c7cde2013-03-02 00:01:32 -0800105};
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800106
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800107displayContent = function(newcontent, more, baseUrl) {
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800108
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800109 $("#content").fadeOut("fast", function() {
110 $(this).replaceWith(newcontent);
111 $("#content").fadeIn("fast");
112 });
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800113
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800114 $("#content-nav").fadeOut("fast", function() {
115 $("#content-nav a").hide();
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800116
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800117 if (PARAMS.offset !== undefined || more !== undefined) {
118 $("#content-nav").fadeIn("fast");
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800119
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800120 if (more !== undefined) {
121 $("#get-more").show();
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800122
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800123 $("#get-more").unbind('click').click(function() {
124 url = baseUrl;
125 url += "&offset=" + more;
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800126
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800127 document.location = url;
128 });
129 }
130 if (PARAMS.offset > 0) {
131 $("#get-less").show();
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800132
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800133 $("#get-less").unbind('click').click(function() {
134 url = baseUrl;
135 if (PARAMS.offset > 5) {
136 url += "&offset=" + (PARAMS.offset - 5);
137 }
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800138
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800139 document.location = url;
140 });
141 }
142 }
143 });
Alexander Afanasyev10babd22013-03-04 13:53:36 -0800144};
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800145
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800146function custom_alert(output_msg, title_msg)
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800147{
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800148 if (!title_msg)
149 title_msg = 'Alert';
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800150
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800151 if (!output_msg)
152 output_msg = 'No Message to Display';
Alexander Afanasyev4c17b482013-03-02 01:32:35 -0800153
Alexander Afanasyeveda3b7a2016-12-25 11:26:40 -0800154 $("<div></div>").html(output_msg).dialog({
155 title: title_msg,
156 resizable: false,
157 modal: true,
158 buttons: {
159 "Ok": function() {
160 $(this).dialog("close");
161 }
162 }
163 });
Alexander Afanasyeve16ed212016-12-25 18:09:44 -0800164}