_onFormLoad does nothing if gui is not ready

This commit is contained in:
Juan Ferrer 2019-09-06 14:54:50 +02:00
parent 5fc168987d
commit 6cb13727a7
3 changed files with 209 additions and 276 deletions

2
debian/changelog vendored
View File

@ -1,4 +1,4 @@
hedera-web (1.406.63) stable; urgency=low
hedera-web (1.406.64) stable; urgency=low
* Initial Release.

View File

@ -4,20 +4,15 @@ var Tpl = require ('./gui.xml');
require('./gui.css');
module.exports = new Class
({
module.exports = new Class({
Extends: Htk.Component,
Properties:
{
conn:
{
Properties: {
conn: {
type: Db.Connection
,set: function (x)
{
,set: function(x) {
this.link({_conn: x}, {'loading-changed': this._onConnLoadChange });
}
,get: function ()
{
,get: function() {
return this._conn;
}
}
@ -34,21 +29,18 @@ module.exports = new Class
,_scrollTimeout: null
,_navbarVisible: true
,initialize: function (props)
{
,initialize: function(props) {
this.builderInitString(Tpl);
this.loadingCount = 0;
this.$('background').onclick = function() {};
this.$('menu-button').addEventListener ('click', function (event)
{
this.$('menu-button').addEventListener('click', function(event) {
event.stopPropagation();
this.showMenu();
}.bind(this));
this.$('left-panel').addEventListener ('click', function (event)
{
this.$('left-panel').addEventListener('click', function(event) {
event.stopPropagation();
});
@ -66,8 +58,7 @@ module.exports = new Class
this.loadMenu();
}
,show: function ()
{
,show: function() {
if (this._shown)
return;
@ -75,8 +66,7 @@ module.exports = new Class
this.doc.body.appendChild(this.node);
Htk.Toast.pushTop(this.$('form-holder'));
if (Vn.isMobile ())
{
if (Vn.isMobile()) {
this._onScrollHandler = this._onScroll.bind(this);
window.addEventListener('scroll', this._onScrollHandler );
}
@ -85,8 +75,7 @@ module.exports = new Class
this.formParam = new Vn.HashParam({key: 'form'});
this.formParam.on('changed', this._onFormChange, this);
if (!localStorage.getItem ('hederaCookies'))
{
if (!localStorage.getItem('hederaCookies')) {
localStorage.setItem('hederaCookies', true);
Htk.Toast.showWarning(_('By using this site you accept cookies'));
}
@ -94,8 +83,7 @@ module.exports = new Class
this.supplantInit();
}
,hide: function ()
{
,hide: function() {
if (!this._shown)
return;
@ -111,31 +99,26 @@ module.exports = new Class
Vn.Node.remove(this.node);
}
,logout: function ()
{
,logout: function() {
this.onLogoutClick();
}
,onLogoutClick: function ()
{
,onLogoutClick: function() {
this._conn.close(this._onConnClose.bind(this));
}
,_onConnClose: function ()
{
,_onConnClose: function() {
this.signalEmit('logout');
}
,_onConnLoadChange: function (conn, isLoading)
{
,_onConnLoadChange: function(conn, isLoading) {
if (isLoading)
this.loaderPush();
else
this.loaderPop();
}
,onMainQueryDone: function (resultSet)
{
,onMainQueryDone: function(resultSet) {
// Retrieving the user name
var userName = resultSet.fetchValue();
@ -158,8 +141,7 @@ module.exports = new Class
var isTesting = !resultSet.fetchValue();
if (isTesting)
{
if (isTesting) {
this.$('dev-info').style.display = 'block';
this.$('version').textContent = Vn.Cookie.get('vnVersion');
}
@ -168,15 +150,11 @@ module.exports = new Class
var res = resultSet.fetchResult();
if (res.next () && res.get ('testDomain'))
{
if (location.host != res.get ('productionDomain'))
{
if (res.next() && res.get('testDomain')) {
if (location.host != res.get('productionDomain')) {
var linkText = 'Old website';
var linkField = 'productionDomain';
}
else
{
} else {
var linkText = 'Test the new website';
var linkField = 'testDomain';
}
@ -184,8 +162,7 @@ module.exports = new Class
Vn.Node.setText(this.$('test-link'), _(linkText));
this.$('test-link').href = '//'+ res.get(linkField);
this.$('test-link').style.display = 'block';
}
else
} else
this.$('test-link').style.display = 'none';
// Loading the default form
@ -193,22 +170,19 @@ module.exports = new Class
this._onFormChange();
}
,loadMenu: function ()
{
,loadMenu: function() {
var sql = 'SELECT * FROM myMenu';
this._conn.execQuery(sql, this._onMenuLoad.bind(this));
}
,_onMenuLoad: function (resultSet)
{
,_onMenuLoad: function(resultSet) {
// Retrieving menu sections
var res = resultSet.fetchResult();
var sectionMap = {};
if (res)
for (var i = 0; res.next (); i++)
{
for (var i = 0; res.next(); i++) {
var parent = res.get('parentFk');
if (!sectionMap[parent])
@ -223,12 +197,10 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Menu
,createMenu: function (res, sectionMap, parent, ul)
{
,createMenu: function(res, sectionMap, parent, ul) {
var sections = sectionMap[parent];
for (var i = 0; i < sections.length; i++)
{
for (var i = 0; i < sections.length; i++) {
res.row = sections[i];
var li = this.createElement('li');
@ -238,8 +210,7 @@ module.exports = new Class
var a = this.createElement('a');
if (res.get ('path'))
{
if (res.get('path')) {
a.href = Vn.Hash.make({'form': res.get('path')});
this.menuOptions[res.get('path')] = a;
}
@ -249,8 +220,7 @@ module.exports = new Class
var formId = res.get('id');
if (sectionMap[formId])
{
if (sectionMap[formId]) {
var submenu = this.createElement('ul');
submenu.className = 'submenu';
li.appendChild(submenu);
@ -265,8 +235,7 @@ module.exports = new Class
}
}
,_onLiMouseHover: function (submenu, parent)
{
,_onLiMouseHover: function(submenu, parent) {
if (this.menuShown)
return;
@ -279,17 +248,14 @@ module.exports = new Class
submenu.style.top = rect.top +'px';
}
,_onLiMouseOut: function ()
{
,_onLiMouseOut: function() {
this.timeout = setTimeout(this.hideSubmenu.bind(this), 160);
}
,hideSubmenu: function ()
{
,hideSubmenu: function() {
var submenu = this.activeSubmenu;
if (submenu)
{
if (submenu) {
Vn.Node.removeClass(submenu, 'popup');
submenu.style.left = '';
submenu.style.top = '';
@ -299,8 +265,7 @@ module.exports = new Class
}
}
,showMenu: function ()
{
,showMenu: function() {
this.showBackground();
Vn.Node.addClass(this.$('left-panel'), 'show');
this.menuShown = true;
@ -309,8 +274,7 @@ module.exports = new Class
this.doc.addEventListener('click', this.hideMenuCallback);
}
,hideMenu: function ()
{
,hideMenu: function() {
if (!this.menuShown)
return;
@ -324,15 +288,13 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Navigation bar
,_onScroll: function ()
{
,_onScroll: function() {
if (this._scrollTimeout === null)
this._scrollTimeout = setTimeout(
this._scrollTimeoutFunc.bind(this), 150);
}
,_scrollTimeoutFunc: function ()
{
,_scrollTimeoutFunc: function() {
if (!this._shown)
return;
@ -340,8 +302,7 @@ module.exports = new Class
var yOffset = Vn.Browser.getPageYOffset();
var showNavbar = this._lastYOffset > yOffset || yOffset < navbar.offsetHeight;
if (showNavbar !== this._navbarVisible)
{
if (showNavbar !== this._navbarVisible) {
if (showNavbar)
var translateY = 0;
else
@ -358,28 +319,24 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Background
,showBackground: function ()
{
,showBackground: function() {
Vn.Node.addClass(this.$('background'), 'show');
}
,hideBackground: function ()
{
,hideBackground: function() {
Vn.Node.removeClass(this.$('background'), 'show');
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Spinner
,loaderPush: function ()
{
,loaderPush: function() {
this.loadingCount++;
if (this.loadingCount == 1)
this.$('loader').start();
}
,loaderPop: function ()
{
,loaderPop: function() {
if (this.loadingCount == 0)
return;
@ -391,8 +348,7 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Forms
,_onFormChange: function ()
{
,_onFormChange: function() {
var formPath = this.formParam.value;
if (!formPath)
@ -402,8 +358,7 @@ module.exports = new Class
this._onFormLoad.bind(this));
}
,openForm: function (formPath, callback)
{
,openForm: function(formPath, callback) {
this.hideMenu();
this.loaderPush();
@ -412,8 +367,7 @@ module.exports = new Class
var newChoosedOption = this.menuOptions[formPath];
if (newChoosedOption)
{
if (newChoosedOption) {
Vn.Node.addClass(newChoosedOption, 'selected');
this.choosedOption = newChoosedOption;
}
@ -423,8 +377,7 @@ module.exports = new Class
var formInfo = this.forms[formPath];
if (!formInfo)
{
if (!formInfo) {
formInfo = new Module('forms', formPath);
this.forms[formPath] = formInfo;
}
@ -432,70 +385,59 @@ module.exports = new Class
formInfo.addCallback(callback);
}
,_onFormLoad: function (formInfo)
{
,_onFormLoad: function(formInfo) {
this.loaderPop();
if (formInfo.error)
{
Htk.Toast.showError (_('Error loading form'));
return Htk.Toast.showError(_('Error loading form'));
if (!this._shown)
return;
}
this.activeForm = new formInfo.klass(this, formInfo);
this.activeForm.open();
}
,setForm: function (form)
{
,setForm: function(form) {
Vn.Node.removeChilds(this.$('form-holder'));
if (form)
{
if (form) {
this.$('form-holder').appendChild(form);
setTimeout(this._onSetFormTimeout.bind(this), 0);
}
}
,_onSetFormTimeout: function ()
{
,_onSetFormTimeout: function() {
Vn.Node.addClass(this.$('form-holder'), 'show');
}
,setTitle: function (title)
{
,setTitle: function(title) {
Vn.Node.removeChilds(this.$('title'));
if (title)
this.$('title').appendChild(title);
}
,setActions: function (actions)
{
,setActions: function(actions) {
Vn.Node.removeChilds(this.$('action-bar'));
if (actions)
this.$('action-bar').appendChild(actions);
}
,closeForm: function ()
{
if (this.activeForm)
{
,closeForm: function() {
if (this.activeForm) {
Vn.Node.removeClass(this.$('form-holder'), 'show');
this.activeForm.close();
this.activeForm.unref();
this.activeForm = null;
}
if (this.activeCss)
{
if (this.activeCss) {
Vn.excludeCss(this.activeCss);
this.activeCss = null;
}
if (this.choosedOption)
{
if (this.choosedOption) {
Vn.Node.removeClass(this.choosedOption, 'selected');
this.choosedOption = null;
}
@ -503,20 +445,17 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Reports
,openReport: function (reportName, batch)
{
,openReport: function(reportName, batch) {
this.loaderPush();
var module = new Module('reports', reportName);
module.addCallback(this._onReportLoad.bind(this, batch));
}
,_onReportLoad: function (batch, module)
{
,_onReportLoad: function(batch, module) {
this.loaderPop();
if (module.error)
{
if (module.error) {
Htk.Toast.showError(_('Error loading report'));
return;
}
@ -527,22 +466,19 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Supplant
,supplantInit: function ()
{
,supplantInit: function() {
var user = sessionStorage.getItem('supplantUser');
if (user != null)
this.supplantUser(user);
}
,supplantUser: function (user, callback)
{
,supplantUser: function(user, callback) {
this._conn.supplantUser(user,
this._onUserSupplant.bind(this, callback, user));
}
,_onUserSupplant: function (callback, user, supplantOk)
{
,_onUserSupplant: function(callback, user, supplantOk) {
if (!supplantOk)
return;
@ -556,15 +492,13 @@ module.exports = new Class
callback();
}
,_onSupplantName: function (resultSet)
{
,_onSupplantName: function(resultSet) {
var userName = resultSet.fetchValue();
Vn.Node.setText(this.$('supplanted'), userName);
Vn.Node.show(this.$('supplant'));
}
,onSupplantExitClick: function ()
{
,onSupplantExitClick: function() {
Vn.Node.hide(this.$('supplant'));
this._conn.supplantEnd();
sessionStorage.removeItem('supplantUser',
@ -575,8 +509,7 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Destroy
,_destroy: function ()
{
,_destroy: function() {
this.hide();
this.parent();
}

View File

@ -1,6 +1,6 @@
{
"name": "hedera-web",
"version": "1.406.63",
"version": "1.406.64",
"description": "Verdnatura web page",
"license": "GPL-3.0",
"repository": {