0
1
Fork 0

Solucionado error en login al actualizar, solucionado fallo al borrar fila en Htk.Repeater

This commit is contained in:
Juan Ferrer Toribio 2016-05-05 17:47:45 +02:00
parent fe070a7e6b
commit 8e42a5e262
13 changed files with 271 additions and 190 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.337-deb8) stable; urgency=low
hedera-web (1.340-deb8) stable; urgency=low
* Initial Release.

View File

@ -12,8 +12,8 @@ Db.CalcSum = new Class
if (this._func)
{
this.form.row = row;
value = this._func (this.form);
this._set.row = row;
value = this._func (this._set);
}
else
value = this._model.getByIndex (row, this.columnIndex);

View File

@ -21,8 +21,8 @@ Db.Calc = new Class
,'row-inserted': this.onRowInsert
});
var form = new Db.Form ({model: x});
this.link ({form: form});
var set = new Db.SimpleIterator ({model: x});
this.link ({_set: set});
}
,get: function ()
{

View File

@ -28,8 +28,8 @@ Db.Conn.implement
({
Extends: Vn.Object
,connected: false
,requestsCount: 0
,_connected: false
,_requestsCount: 0
/**
* Initilizes the connection object.
@ -47,92 +47,71 @@ Db.Conn.implement
* @param {Boolean} remember Specifies if the user should be remembered
* @param {Function} openCallback The function to call when operation is done
**/
,open: function (user, pass, remember, openCallback, guest)
,open: function (user, pass, remember, callback, guest)
{
this.signalEmit ('loading-changed', true);
var request = new Vn.HttpRequest ();
request.add ({'action': 'login'});
if (user != null)
{
request.add
({
var params = {
'user': user
,'password': pass
,'remember': remember
});
};
}
else if (guest)
request.add ({'guest': true});
var params = {'guest': true};
request.send ('rest.php',
this.opened.bind (this, request, openCallback));
var request = new Vn.JsonRequest ('login');
request.send (params,
this._onOpen.bind (this, callback));
}
/*
* Called when open operation is done.
*/
,opened: function (request, openCallback, success)
,_onOpen: function (callback, request, json, error)
{
var error = null;
var openSuccess = false;
if (success)
try {
var json = request.getJson ();
openSuccess = json.data == true;
if (json.error)
error = new Vn.Error (
json.error.domain,
json.error.code,
json.error.message);
}
catch (e)
{
error = e;
}
if (openSuccess)
{
this.connected = true;
this.signalEmit ('openned');
}
this._connected = json == true;
this.signalEmit ('loading-changed', false);
if (this._connected)
this.signalEmit ('openned');
if (openCallback)
openCallback (this, openSuccess, error);
if (error)
this.signalEmit ('error', error);
if (callback)
callback (this, this._connected, error);
}
/**
* Closes the connection to the database.
*
* @param {Function} closeCallback The function to call when operation is done
* @param {Function} callback The function to call when operation is done
**/
,close: function (closeCallback)
,close: function (callback)
{
this.signalEmit ('loading-changed', true);
var request = new Vn.HttpRequest ();
request.add ({'action': 'logout'});
request.send ('rest.php',
this.closed.bind (this, closeCallback));
var request = new Vn.JsonRequest ('logout');
request.send (null,
this._onClose.bind (this, callback));
}
/*
* Called when close operation is done.
*/
,closed: function (closeCallback)
,_onClose: function (callback, request, json, error)
{
this.connected = false;
this.signalEmit ('closed');
this._connected = false;
this.signalEmit ('loading-changed', false);
this.signalEmit ('closed');
if (closeCallback)
closeCallback (this);
if (error)
this.signalEmit ('error', error);
if (callback)
callback (this, json == true, error);
}
/**
@ -143,19 +122,14 @@ Db.Conn.implement
**/
,execSql: function (sql, callback)
{
this.requestsCount++;
this._requestsCount++;
if (this.requestsCount == 1)
if (this._requestsCount === 1)
this.signalEmit ('loading-changed', true);
var httpRequest = new Vn.HttpRequest ()
httpRequest.add
({
'action': 'query'
,'sql': sql
});
httpRequest.send ('rest.php',
this.execDone.bind (this, httpRequest, callback));
var request = new Vn.JsonRequest ('query');
request.send ({'sql': sql},
this._onExec.bind (this, callback));
}
/**
@ -189,41 +163,25 @@ Db.Conn.implement
{
return new Date (value * 1000);
}
/*
* Called when a query is executed.
*/
,execDone: function (httpRequest, callback, success)
,_onExec: function (callback, request, json, error)
{
var e;
var error = null;
var results = null;
this.requestsCount--;
this._requestsCount--;
if (this.requestsCount == 0)
if (this._requestsCount === 0)
this.signalEmit ('loading-changed', false);
if (!success)
{
error = new Vn.Error ('Conn', 'connError', _('ConnError'));
this.signalEmit ('error', error);
}
else
if (json)
try {
var json = httpRequest.getJson ();
results = json.data;
if (json.error !== null)
error = new Vn.Error (json.error.domain,
json.error.code, json.error.message);
if (results instanceof Array)
for (var i = 0; i < results.length; i++)
if (results[i] !== true)
if (json && json instanceof Array)
for (var i = 0; i < json.length; i++)
if (json[i] !== true)
{
var data = results[i].data;
var columns = results[i].columns;
var data = json[i].data;
var columns = json[i].columns;
for (var j = 0; j < columns.length; j++)
{
@ -254,13 +212,13 @@ Db.Conn.implement
{
error = e;
}
if (error)
this.signalEmit ('error', error);
if (callback)
try {
callback (new Db.ResultSet (results, error));
callback (new Db.ResultSet (json, error));
}
catch (e)
{

View File

@ -8,6 +8,7 @@ Vn.includeLib ('db',
,'result-set'
,'model'
,'iterator'
,'simple-iterator'
,'form'
,'param'
,'query'

View File

@ -0,0 +1,70 @@
/**
* A light iterator for models.
**/
Db.SimpleIterator = new Class
({
Extends: Vn.Object
,Implements: Db.Iterator
,Properties:
{
/**
* The model associated to this form.
**/
model:
{
type: Db.Model
,set: function (x)
{
this._model = x;
}
,get: function ()
{
return this._model;
}
},
/**
* The row where the form positioned, has -1 if the row is unselected.
**/
row:
{
type: Number
,set: function (x)
{
this._row = x;
}
,get: function ()
{
return this._row;
}
},
/**
* The number of rows in the form.
**/
numRows:
{
type: Number
,get: function ()
{
if (this._model)
return this._model.numRows;
return 0;
}
},
/**
* Checks if the form data is ready.
**/
ready:
{
type: Boolean
,get: function ()
{
if (this._model)
return this._model.ready;
return false;
}
}
}
});

View File

@ -107,8 +107,6 @@ Vn.App = new Class
var error = new Error (message);
error.fileName = file;
error.lineNumber = line;
Htk.Toast.showError (_('There was an internal error'));
this._notifyError (error);
}
@ -123,16 +121,20 @@ Vn.App = new Class
switch (error.domain)
{
case 'Auth':
Htk.Toast.showError (_('You\'ve been too idle'));
if (error.code === 'badLogin')
Htk.Toast.showError (_('Invalid login'));
else if (error.code === 'sessionExpired')
Htk.Toast.showError (_('You\'ve been too idle'));
if (this._gui)
this._gui.logout ();
break;
break;
case 'Version':
this._newVersion (error);
break;
break;
case 'User':
Htk.Toast.showError (error.message);
break;
break;
default:
console.error (error.message);
Htk.Toast.showError (_('There was an internal error'));
@ -140,7 +142,6 @@ Vn.App = new Class
else
{
console.error (error);
Htk.Toast.showError (_('There was an internal error'));
this._notifyError (error);
}
}
@ -174,18 +175,20 @@ Vn.App = new Class
,_notifyError: function (error)
{
if (error instanceof Error)
{
var httpRequest = new Vn.HttpRequest ()
httpRequest.add
({
'file': error.fileName
,'line': error.lineNumber
,'message': error.message
,'stack': error.stack
});
httpRequest.send ('log.php');
}
Htk.Toast.showError (_('There was an internal error'));
var params = {
'file': error.fileName
,'line': error.lineNumber
,'message': error.message
,'stack': error.stack
};
var request = new XMLHttpRequest ();
request.open ('post', 'log.php', true);
request.setRequestHeader ('Content-Type',
'application/x-www-form-urlencoded');
request.send (Vn.Url.makeUri (params));
}
,_freeLogin: function ()

View File

@ -92,10 +92,7 @@ Vn.Login = new Class
if (success)
this.signalEmit ('login');
else
if (error instanceof Vn.Error && error.domain === 'Auth')
Htk.Toast.showError (_('Invalid login'));
this._focusUserInput ();
this._focusUserInput ();
}
});

View File

@ -34,22 +34,53 @@ Vn.Tpv = new Class
{
if (amount > 0)
{
var request = new Vn.HttpRequest ();
request.add
({
'action': 'tpv'
,'amount': parseInt (amount)
var params = {
'amount': parseInt (amount)
,'urlOk': this._makeUrl ('ok')
,'urlKo': this._makeUrl ('ko')
,'company': company
});
};
request.send ('rest.php',
this._onTransactionStart.bind (this, request));
var request = new Vn.JsonRequest ('tpv');
request.send (params,
this._onTransactionStart.bind (this));
}
else if (!isNaN (amount))
Htk.Toast.showError (_('AmountError'));
}
,_onTransactionStart: function (request, json, error)
{
if (json)
{
var form = document.createElement ('form');
form.method = 'post';
form.action = json.url;
document.body.appendChild (form);
var fieldsMap =
{
'Ds_SignatureVersion': 'HMAC_SHA256_V1'
,'Ds_MerchantParameters': json.params
,'Ds_Signature': json.signature
};
for (var field in fieldsMap)
{
var input = document.createElement ('input');
input.type = 'hidden';
input.name = field;
form.appendChild (input);
if (fieldsMap[field])
input.value = fieldsMap[field];
}
form.submit ();
}
else
Htk.Toast.showWarning (_('PayError'));
}
,retryPay: function ()
{
@ -74,58 +105,6 @@ Vn.Tpv = new Class
Htk.Toast.showError (_('AmountError'));
}
,_onTransactionStart: function (request, success)
{
var data = null;
var error = null;
if (success)
try {
var json = request.getJson ();
var data = json.data;
if (json.error)
error = new Vn.Error (
json.error.domain,
json.error.code,
json.error.message);
}
catch (e)
{
error = e;
}
if (success && data)
{
var form = document.createElement ('form');
form.method = 'post';
form.action = data.url;
document.body.appendChild (form);
var fieldsMap =
{
'Ds_SignatureVersion': 'HMAC_SHA256_V1'
,'Ds_MerchantParameters': data.params
,'Ds_Signature': data.signature
};
for (var field in fieldsMap)
{
var input = document.createElement ('input');
input.type = 'hidden';
input.name = field;
form.appendChild (input);
if (fieldsMap[field])
input.value = fieldsMap[field];
}
form.submit ();
}
else
Htk.Toast.showWarning (_('PayError'));
}
,_makeUrl: function (status, order)
{
var path = location.protocol +'//'+ location.host;

View File

@ -23,8 +23,8 @@ Htk.Grid = new Class
,'updatable-changed': this.onUpdatableChange
});
var form = new Db.Form ({model: x});
this.link ({form: form});
var set = new Db.SimpleIterator ({model: x});
this.link ({_set: set});
this.onUpdatableChange ();
this.onModelChange ();
@ -61,7 +61,7 @@ Htk.Grid = new Class
}
,_model: null
,form: null
,_set: null
,columns: new Array ()
,internalColumn: null
,internalColumns: 0
@ -120,8 +120,8 @@ Htk.Grid = new Class
if (column.renderer)
{
this.form.row = row;
column.renderer (column, this.form);
this._set.row = row;
column.renderer (column, this._set);
}
return column.render (tr);

View File

@ -106,27 +106,27 @@ Htk.Repeater = new Class
,getForm: function (index)
{
return this._childsData[index].form;
return this._childsData[index].set;
}
,_buildBox: function (index)
{
var form = new Db.Form ({
var set = new Db.SimpleIterator ({
model: this._model,
row: index
});
this._builder.add (this._formId, form);
this._builder.add (this._formId, set);
var res = this._builder.load ();
res.link ();
this._childsData.push ({
builder: res,
form: form
set: set
});
if (this._renderer)
this._renderer (res, form);
this._renderer (res, set);
return res.getMain ();
}
@ -200,12 +200,17 @@ Htk.Repeater = new Class
{
Vn.Node.remove (this._container.childNodes[row]);
this._unrefChildData (row);
this._childsData.splice (row, 1);
for (var i = row; i < this._model.numRows; i++)
this._childsData[i].set.row = i;
this._showNoRecordsFound ();
}
,_onRowUpdate: function (model, row, columns)
{
// this.form[row].signalEmit ('iter-changed');
this._childsData[row].set.iterChanged ();
}
,_onRowInsert: function (model, row)
@ -224,7 +229,7 @@ Htk.Repeater = new Class
,_unrefChildData: function (index)
{
var childData = this._childsData[index];
childData.form.unref ();
childData.set.unref ();
childData.builder.unref ();
}

68
web/js/vn/json-request.js Normal file
View File

@ -0,0 +1,68 @@
/**
* Handler for JSON rest requests.
**/
Vn.JsonRequest = new Class
({
initialize: function (methodName)
{
this._methodName = methodName;
}
,send: function (params, callback)
{
var url = 'rest.php?action='+ encodeURIComponent (this._methodName);
var request = new XMLHttpRequest ();
request.open ('post', url, true);
request.setRequestHeader ('Content-Type',
'application/x-www-form-urlencoded');
request.onreadystatechange =
this._onStateChange.bind (this, request, callback);
request.send (Vn.Url.makeUri (params));
}
,_onStateChange: function (request, callback)
{
if (request.readyState !== 4)
return;
var jsData = null;
var error = null;
try {
if (request.status !== 200)
throw new Error (request.statusText);
var json = JSON.parse (request.responseText);
var jsData = json.data;
var jsError = json.error;
if (jsError)
throw new Vn.Error (
jsError.domain,
jsError.code,
jsError.message);
}
catch (e)
{
jsData = null;
error = e;
}
if (callback)
callback (this, jsData, error);
}
,sendForm: function (form, callback)
{
var params = {};
var elements = form.elements;
for (var i = 0; i < elements.length; i++)
if (elements[i].name)
params[elements[i].name] = elements[i].value;
this.send (params, callback);
}
});

View File

@ -16,6 +16,6 @@ Vn.includeLib ('vn',
,'hash-param'
,'node'
,'builder'
,'http-request'
,'json-request'
]);