Solucionado error en login al actualizar, solucionado fallo al borrar fila en Htk.Repeater
This commit is contained in:
parent
fe070a7e6b
commit
8e42a5e262
|
@ -1,4 +1,4 @@
|
|||
hedera-web (1.337-deb8) stable; urgency=low
|
||||
hedera-web (1.340-deb8) stable; urgency=low
|
||||
|
||||
* Initial Release.
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 ()
|
||||
{
|
||||
|
|
|
@ -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 (openCallback)
|
||||
openCallback (this, openSuccess, error);
|
||||
if (this._connected)
|
||||
this.signalEmit ('openned');
|
||||
|
||||
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._connected = false;
|
||||
this.signalEmit ('loading-changed', false);
|
||||
this.signalEmit ('closed');
|
||||
|
||||
this.signalEmit ('loading-changed', false);
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -193,37 +167,21 @@ Db.Conn.implement
|
|||
/*
|
||||
* 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++)
|
||||
{
|
||||
|
@ -260,7 +218,7 @@ Db.Conn.implement
|
|||
|
||||
if (callback)
|
||||
try {
|
||||
callback (new Db.ResultSet (results, error));
|
||||
callback (new Db.ResultSet (json, error));
|
||||
}
|
||||
catch (e)
|
||||
{
|
||||
|
|
|
@ -8,6 +8,7 @@ Vn.includeLib ('db',
|
|||
,'result-set'
|
||||
,'model'
|
||||
,'iterator'
|
||||
,'simple-iterator'
|
||||
,'form'
|
||||
,'param'
|
||||
,'query'
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
@ -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,7 +121,11 @@ Vn.App = new Class
|
|||
switch (error.domain)
|
||||
{
|
||||
case 'Auth':
|
||||
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;
|
||||
|
@ -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
|
||||
({
|
||||
Htk.Toast.showError (_('There was an internal error'));
|
||||
|
||||
var params = {
|
||||
'file': error.fileName
|
||||
,'line': error.lineNumber
|
||||
,'message': error.message
|
||||
,'stack': error.stack
|
||||
});
|
||||
httpRequest.send ('log.php');
|
||||
}
|
||||
};
|
||||
|
||||
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 ()
|
||||
|
|
|
@ -92,9 +92,6 @@ 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 ();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -34,23 +34,54 @@ 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 ()
|
||||
{
|
||||
var batch = new Sql.Batch ();
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 ();
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
|
|
@ -16,6 +16,6 @@ Vn.includeLib ('vn',
|
|||
,'hash-param'
|
||||
,'node'
|
||||
,'builder'
|
||||
,'http-request'
|
||||
,'json-request'
|
||||
]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue