Skip to content
Snippets Groups Projects
Commit dd3abf5f authored by Robert Anderson's avatar Robert Anderson
Browse files

Use sprintf.js, util.js from js/custom/

parent eff8761a
No related branches found
No related tags found
No related merge requests found
/**
* sprintf() for JavaScript v.0.4
*
* Copyright (c) 2007 Alexandru Marasteanu <http://alexei.417.ro/>
* Thanks to David Baird (unit test and patch).
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place, Suite 330, Boston, MA 02111-1307 USA
*/
function str_repeat(i, m) { for (var o = []; m > 0; o[--m] = i); return(o.join('')); }
function sprintf () {
var i = 0, a, f = arguments[i++], o = [], m, p, c, x;
while (f) {
if (m = /^[^\x25]+/.exec(f)) o.push(m[0]);
else if (m = /^\x25{2}/.exec(f)) o.push('%');
else if (m = /^\x25(?:(\d+)\$)?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-fosuxX])/.exec(f)) {
if (((a = arguments[m[1] || i++]) == null) || (a == undefined)) throw("Too few arguments.");
if (/[^s]/.test(m[7]) && (typeof(a) != 'number'))
throw("Expecting number but found " + typeof(a));
switch (m[7]) {
case 'b': a = a.toString(2); break;
case 'c': a = String.fromCharCode(a); break;
case 'd': a = parseInt(a); break;
case 'e': a = m[6] ? a.toExponential(m[6]) : a.toExponential(); break;
case 'f': a = m[6] ? parseFloat(a).toFixed(m[6]) : parseFloat(a); break;
case 'o': a = a.toString(8); break;
case 's': a = ((a = String(a)) && m[6] ? a.substring(0, m[6]) : a); break;
case 'u': a = Math.abs(a); break;
case 'x': a = a.toString(16); break;
case 'X': a = a.toString(16).toUpperCase(); break;
}
a = (/[def]/.test(m[7]) && m[2] && a > 0 ? '+' + a : a);
c = m[3] ? m[3] == '0' ? '0' : m[3].charAt(1) : ' ';
x = m[5] - String(a).length;
p = m[5] ? str_repeat(c, x) : '';
o.push(m[4] ? a + p : p + a);
}
else throw ("Huh ?!");
f = f.substring(m[0].length);
}
return o.join('');
}
/* Generate a random password */
function getRandomPass(len) {
var keylist="abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789"
var ret=''
for (i = 0; i < len; i++)
ret += keylist.charAt( Math.floor(Math.random() * keylist.length) )
return ret
}
......@@ -177,6 +177,10 @@ function showAdminUserLogsWindow(id) {
header: "Output Mbyte",
dataIndex: 'AcctOutputMbyte'
},
{
header: "Session Uptime",
dataIndex: 'AcctSessionTime'
},
{
header: "Term. Reason",
dataIndex: 'ConnectTermReason'
......@@ -219,6 +223,7 @@ function showAdminUserLogsWindow(id) {
{type: 'string', dataIndex: 'FramedIPAddress'},
{type: 'numeric', dataIndex: 'AcctInputMbyte'},
{type: 'numeric', dataIndex: 'AcctOutputMbyte'},
{type: 'numeric', dataIndex: 'AcctSessionTime'},
{type: 'string', dataIndex: 'ConnectTermReason'}
]
}
......@@ -229,22 +234,89 @@ function showAdminUserLogsWindow(id) {
store.on('load',function() {
var inputTotal = store.sum('AcctInputMbyte');
var outputTotal = store.sum('AcctOutputMbyte');
var uptimeTotal = store.sum('AcctSessionTime');
var userCap = 3000;
var userTopups = 1000;
// Total up into this ...
var userTotalAllowed = userCap + userTopups;
var userUsage = inputTotal + outputTotal;
var userLeft = userTotalAllowed - userUsage;
var searchForm = adminUserLogsWindow.getComponent('search-form');
var afterField = (searchForm.getForm().findField('after')).getValue();
var beforeField = (searchForm.getForm().findField('before')).getValue();
var trafficCap;
var uptimeCap;
var trafficTopups;
var uptimeTopups;
var response;
// Mask parent window
adminUserLogsWindow.getEl().mask();
uxAjaxRequest(
adminUserLogsWindow,
{
params: {
From: afterField,
To: beforeField,
ID: id,
SOAPUsername: globalConfig.soap.username,
SOAPPassword: globalConfig.soap.password,
SOAPAuthType: globalConfig.soap.authtype,
SOAPModule: 'AdminUserLogs',
SOAPFunction: 'getAdminUserLogsSummary',
SOAPParams: '0:ID,0:From,0:To'
},
customSuccess: function (result) {
response = Ext.decode(result.responseText);
var form = adminUserLogsWindow.getComponent('summary-form');
var summaryTotal = form.getForm().findField('summaryTotal');
trafficCap = response.data.trafficCap;
uptimeCap = response.data.uptimeCap;
trafficTopups = response.data.trafficTopups;
uptimeTopups = response.data.uptimeTopups;
summaryTotal.setValue(
sprintf('Cap Total: %6d\nTopups : %6d\n-----------------\n %6d\n-----------------\nUsage : %6d\n=================\nAvailable: %6d',userCap,userTopups,userTotalAllowed,userUsage,userLeft)
);
// Total up traffic
var trafficTotalAllowed;
if (trafficCap < 0) {
trafficTotalAllowed = trafficTopups;
} else {
trafficTotalAllowed = trafficCap + trafficTopups;
}
var trafficUsage = inputTotal + outputTotal;
var trafficRemaining = trafficTotalAllowed - trafficUsage;
var form = adminUserLogsWindow.getComponent('summary-form');
var summaryTotal = form.getForm().findField('summaryTotal');
// Format string before printing
var summaryString = '';
if (trafficCap == -1) {
trafficCap = 'Prepaid';
summaryString += sprintf(
'Traffic Cap: %s Traffic Topups: %d\n------------------------------------\n'+
'Allowed: %d Used: %d\n-------------------------------\nRemaining: %d',
trafficCap,trafficTopups,trafficTotalAllowed,trafficUsage,trafficRemaining
);
} else if (trafficCap == 0) {
summaryString += sprintf(
'Traffic Cap: Uncapped\n---------------------------------\nUsed: %d',
trafficUsage
);
} else {
summaryString += sprintf(
'Traffic Cap: %d Traffic Topups: %d\n------------------------------------\n'+
'Allowed: %d Used: %d\n-------------------------------\nRemaining: %d',
trafficCap,trafficTopups,trafficTotalAllowed,trafficUsage,trafficRemaining
);
}
alert(summaryString);
summaryTotal.setValue(summaryString);
},
failure: function (result) {
Ext.MessageBox.alert('Failed', 'Couldn\'t fetch data: '+result.date);
},
});
});
adminUserLogsWindow.show();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment