Commit 368bdac7 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Move the javascript function reprduration from app.js to the view grid.

parent 04765b07
......@@ -28,50 +28,6 @@ Ext.require('TrackEvents.form.field.UserData');
Ext.require('TrackEvents.form.field.UserDataMultiDefault');
Ext.require('TrackEvents.form.plugin.UserDataConsistency');
/**
* Global function vonverting a duration in nanosecond into a string.
*
* @param {Number} value
* The duration in seconds
*
* @return {String}
* The duration express as the number of year + the number of months
* e.g. "3y + 09m"
*
*/
reprDuration = function (value) {
"use strict";
var duration = value,
month, nd, nm, ny, rep, year;
// duration of year and month in seconds
year = 365 * 24 * 3600;
month = year / 12;
// number of years and months
ny = Math.floor(duration / year);
nm = Math.floor((duration - ny * year) / month);
// format the number of month
nm = Ext.String.leftPad(nm.toString(), 2, '0');
// format the response
if (ny > 0) {
rep = Ext.String.format("{0}y + {1}m", ny, nm);
} else if (nm > 0) {
rep = Ext.String.format("{0}m", nm);
} else {
nd = duration / (24 * 3600);
rep = Ext.String.leftPad(nd.toString(), 2, '0');
}
return rep;
};
Ext.onReady(function(){
"use strict";
......
......@@ -31,6 +31,50 @@
}}
<script type="text/javascript">
/**
* Helper function to convert a duration in nanosecond into a string.
*
* @param {Number} value
* The duration in seconds
*
* @return {String}
* The duration express as the number of year + the number of months
* e.g. "3y + 09m"
*
*/
function reprDuration(value) {
"use strict";
var duration = value,
month, nd, nm, ny, rep, year;
// duration of year and month in seconds
year = 365 * 24 * 3600;
month = year / 12;
// number of years and months
ny = Math.floor(duration / year);
nm = Math.floor((duration - ny * year) / month);
// format the number of month
nm = Ext.String.leftPad(nm.toString(), 2, '0');
// format the response
if (ny > 0) {
rep = Ext.String.format("{0}y + {1}m", ny, nm);
} else if (nm > 0) {
rep = Ext.String.format("{0}m", nm);
} else {
nd = duration / (24 * 3600);
rep = Ext.String.leftPad(nd.toString(), 2, '0');
}
return rep;
}
var cfgGrid = {{=XML(cfg_grid)}},
cfgStore = {{=XML(cfg_store)}},
columns = cfgGrid.columns,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment