Revision 0e2122e7 snf-cyclades-app/synnefo/ui/new_ui/ui/app/helpers/helpers.js
b/snf-cyclades-app/synnefo/ui/new_ui/ui/app/helpers/helpers.js | ||
---|---|---|
1 |
Ember.Handlebars.helper('status-to-text', function(value) { |
|
2 |
return statusText[value]; |
|
3 |
}, 'status'); |
|
4 |
|
|
5 |
Ember.Handlebars.registerHelper('myrender', function(name, contextString, options) { |
|
6 |
// controller option set ??? |
|
7 |
if (options.hash.controller) { |
|
8 |
// resolve string from current context |
|
9 |
var resolvedControllerName = Ember.Handlebars.get(options.contexts[0], options.hash.controller, options); |
|
10 |
if (resolvedControllerName) { |
|
11 |
options.hash.controller = resolvedControllerName; |
|
12 |
} |
|
13 |
} |
|
14 |
// call ember render helper |
|
15 |
return Ember.Handlebars.helpers.render.call(this, name, contextString, options); |
|
16 |
}); |
|
17 |
|
|
18 |
|
|
19 |
Ember.Handlebars.helper('bytes-to-human',function (value) { |
|
20 |
function humanFileSize(bytes, si) { |
|
21 |
var thresh = si ? 1000 : 1024; |
|
22 |
if(bytes < thresh) return bytes + ' B'; |
|
23 |
var units = si ? ['kB','MB','GB','TB','PB','EB','ZB','YB'] : ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']; |
|
24 |
var u = -1; |
|
25 |
do { |
|
26 |
bytes /= thresh; |
|
27 |
++u; |
|
28 |
} while(bytes >= thresh); |
|
29 |
return bytes.toFixed(1)+' '+units[u]; |
|
30 |
} |
|
31 |
console.log(value); |
|
32 |
return humanFileSize(value,false); |
|
33 |
}, 'value'); |
Also available in: Unified diff