_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. * Initial Release.

View File

@ -1,23 +1,18 @@
var Module = require ('./module'); var Module = require('./module');
var Tpl = require ('./gui.xml'); var Tpl = require('./gui.xml');
require ('./gui.css'); require('./gui.css');
module.exports = new Class module.exports = new Class({
({
Extends: Htk.Component, Extends: Htk.Component,
Properties: Properties: {
{ conn: {
conn:
{
type: Db.Connection type: Db.Connection
,set: function (x) ,set: function(x) {
{ this.link({_conn: x}, {'loading-changed': this._onConnLoadChange });
this.link ({_conn: x}, {'loading-changed': this._onConnLoadChange });
} }
,get: function () ,get: function() {
{
return this._conn; return this._conn;
} }
} }
@ -34,25 +29,22 @@ module.exports = new Class
,_scrollTimeout: null ,_scrollTimeout: null
,_navbarVisible: true ,_navbarVisible: true
,initialize: function (props) ,initialize: function(props) {
{ this.builderInitString(Tpl);
this.builderInitString (Tpl);
this.loadingCount = 0; this.loadingCount = 0;
this.$('background').onclick = function () {}; this.$('background').onclick = function() {};
this.$('menu-button').addEventListener ('click', function (event) this.$('menu-button').addEventListener('click', function(event) {
{ event.stopPropagation();
event.stopPropagation (); this.showMenu();
this.showMenu (); }.bind(this));
}.bind (this));
this.$('left-panel').addEventListener ('click', function (event) this.$('left-panel').addEventListener('click', function(event) {
{ event.stopPropagation();
event.stopPropagation ();
}); });
this.parent (props); this.parent(props);
this.$('social-bar').conn = this._conn; this.$('social-bar').conn = this._conn;
@ -61,287 +53,256 @@ module.exports = new Class
+'SELECT url FROM imageConfig;' +'SELECT url FROM imageConfig;'
+'SELECT dbproduccion FROM vn2008.tblContadores;' +'SELECT dbproduccion FROM vn2008.tblContadores;'
+'SELECT productionDomain, testDomain FROM config;'; +'SELECT productionDomain, testDomain FROM config;';
this._conn.execQuery (sql, this.onMainQueryDone.bind (this)); this._conn.execQuery(sql, this.onMainQueryDone.bind(this));
this.loadMenu (); this.loadMenu();
} }
,show: function () ,show: function() {
{
if (this._shown) if (this._shown)
return; return;
this._shown = true; this._shown = true;
this.doc.body.appendChild (this.node); this.doc.body.appendChild(this.node);
Htk.Toast.pushTop (this.$('form-holder')); Htk.Toast.pushTop(this.$('form-holder'));
if (Vn.isMobile ()) if (Vn.isMobile()) {
{ this._onScrollHandler = this._onScroll.bind(this);
this._onScrollHandler = this._onScroll.bind (this); window.addEventListener('scroll', this._onScrollHandler );
window.addEventListener ('scroll', this._onScrollHandler );
} }
this.hash = Vn.Hash; this.hash = Vn.Hash;
this.formParam = new Vn.HashParam ({key: 'form'}); this.formParam = new Vn.HashParam({key: 'form'});
this.formParam.on ('changed', this._onFormChange, this); this.formParam.on('changed', this._onFormChange, this);
if (!localStorage.getItem ('hederaCookies')) if (!localStorage.getItem('hederaCookies')) {
{ localStorage.setItem('hederaCookies', true);
localStorage.setItem ('hederaCookies', true); Htk.Toast.showWarning(_('By using this site you accept cookies'));
Htk.Toast.showWarning (_('By using this site you accept cookies'));
} }
this.supplantInit (); this.supplantInit();
} }
,hide: function () ,hide: function() {
{
if (!this._shown) if (!this._shown)
return; return;
this._shown = false; this._shown = false;
if (Vn.isMobile ()) if (Vn.isMobile())
window.removeEventListener ('scroll', this._onScrollHandler); window.removeEventListener('scroll', this._onScrollHandler);
Htk.Toast.popTop (); Htk.Toast.popTop();
this.formParam.unref (); this.formParam.unref();
this.closeForm (); this.closeForm();
this.hideMenu (); this.hideMenu();
Vn.Node.remove (this.node); Vn.Node.remove(this.node);
} }
,logout: function () ,logout: function() {
{ this.onLogoutClick();
this.onLogoutClick ();
} }
,onLogoutClick: function () ,onLogoutClick: function() {
{ this._conn.close(this._onConnClose.bind(this));
this._conn.close (this._onConnClose.bind (this));
} }
,_onConnClose: function () ,_onConnClose: function() {
{ this.signalEmit('logout');
this.signalEmit ('logout');
} }
,_onConnLoadChange: function (conn, isLoading) ,_onConnLoadChange: function(conn, isLoading) {
{
if (isLoading) if (isLoading)
this.loaderPush (); this.loaderPush();
else else
this.loaderPop (); this.loaderPop();
} }
,onMainQueryDone: function (resultSet) ,onMainQueryDone: function(resultSet) {
{
// Retrieving the user name // Retrieving the user name
var userName = resultSet.fetchValue (); var userName = resultSet.fetchValue();
Vn.Node.setText (this.$('user-name'), userName); Vn.Node.setText(this.$('user-name'), userName);
// Retrieving configuration parameters // Retrieving configuration parameters
var res = resultSet.fetchResult (); var res = resultSet.fetchResult();
var columns = res.columns; var columns = res.columns;
if (res.next ()) if (res.next())
for (var i = 0; i < res.columns.length; i++) for (var i = 0; i < res.columns.length; i++)
Vn.Config[columns[i].name] = res.get (columns[i].name); Vn.Config[columns[i].name] = res.get(columns[i].name);
// Retrieving configuration parameters // Retrieving configuration parameters
Vn.Config.imageUrl = resultSet.fetchValue (); Vn.Config.imageUrl = resultSet.fetchValue();
// Retrieving configuration parameters // Retrieving configuration parameters
var isTesting = !resultSet.fetchValue (); var isTesting = !resultSet.fetchValue();
if (isTesting) if (isTesting) {
{
this.$('dev-info').style.display = 'block'; this.$('dev-info').style.display = 'block';
this.$('version').textContent = Vn.Cookie.get ('vnVersion'); this.$('version').textContent = Vn.Cookie.get('vnVersion');
} }
// Retrieving configuration parameters // Retrieving configuration parameters
var res = resultSet.fetchResult (); var res = resultSet.fetchResult();
if (res.next () && res.get ('testDomain')) if (res.next() && res.get('testDomain')) {
{ if (location.host != res.get('productionDomain')) {
if (location.host != res.get ('productionDomain'))
{
var linkText = 'Old website'; var linkText = 'Old website';
var linkField = 'productionDomain'; var linkField = 'productionDomain';
} } else {
else
{
var linkText = 'Test the new website'; var linkText = 'Test the new website';
var linkField = 'testDomain'; var linkField = 'testDomain';
} }
Vn.Node.setText (this.$('test-link'), _(linkText)); Vn.Node.setText(this.$('test-link'), _(linkText));
this.$('test-link').href = '//'+ res.get (linkField); this.$('test-link').href = '//'+ res.get(linkField);
this.$('test-link').style.display = 'block'; this.$('test-link').style.display = 'block';
} } else
else
this.$('test-link').style.display = 'none'; this.$('test-link').style.display = 'none';
// Loading the default form // Loading the default form
this._onFormChange (); this._onFormChange();
} }
,loadMenu: function () ,loadMenu: function() {
{
var sql = 'SELECT * FROM myMenu'; var sql = 'SELECT * FROM myMenu';
this._conn.execQuery (sql, this._onMenuLoad.bind (this)); this._conn.execQuery(sql, this._onMenuLoad.bind(this));
} }
,_onMenuLoad: function (resultSet) ,_onMenuLoad: function(resultSet) {
{
// Retrieving menu sections // Retrieving menu sections
var res = resultSet.fetchResult (); var res = resultSet.fetchResult();
var sectionMap = {}; var sectionMap = {};
if (res) if (res)
for (var i = 0; res.next (); i++) for (var i = 0; res.next(); i++) {
{ var parent = res.get('parentFk');
var parent = res.get ('parentFk');
if (!sectionMap[parent]) if (!sectionMap[parent])
sectionMap[parent] = []; sectionMap[parent] = [];
sectionMap[parent].push (i); sectionMap[parent].push(i);
} }
Vn.Node.removeChilds (this.$('main-menu')); Vn.Node.removeChilds(this.$('main-menu'));
this.createMenu (res, sectionMap, null, this.$('main-menu')); this.createMenu(res, sectionMap, null, this.$('main-menu'));
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Menu //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Menu
,createMenu: function (res, sectionMap, parent, ul) ,createMenu: function(res, sectionMap, parent, ul) {
{
var sections = sectionMap[parent]; var sections = sectionMap[parent];
for (var i = 0; i < sections.length; i++) for (var i = 0; i < sections.length; i++) {
{
res.row = sections[i]; res.row = sections[i];
var li = this.createElement ('li'); var li = this.createElement('li');
ul.appendChild (li); ul.appendChild(li);
var text = this.createTextNode (_(res.get ('description'))); var text = this.createTextNode(_(res.get('description')));
var a = this.createElement ('a'); var a = this.createElement('a');
if (res.get ('path')) if (res.get('path')) {
{ a.href = Vn.Hash.make({'form': res.get('path')});
a.href = Vn.Hash.make ({'form': res.get ('path')}); this.menuOptions[res.get('path')] = a;
this.menuOptions[res.get ('path')] = a;
} }
a.appendChild (text); a.appendChild(text);
li.appendChild (a); li.appendChild(a);
var formId = res.get ('id'); var formId = res.get('id');
if (sectionMap[formId]) if (sectionMap[formId]) {
{ var submenu = this.createElement('ul');
var submenu = this.createElement ('ul');
submenu.className = 'submenu'; submenu.className = 'submenu';
li.appendChild (submenu); li.appendChild(submenu);
li.addEventListener ('mouseover', li.addEventListener('mouseover',
this._onLiMouseHover.bind (this, submenu, a)); this._onLiMouseHover.bind(this, submenu, a));
li.addEventListener ('mouseout', li.addEventListener('mouseout',
this._onLiMouseOut.bind (this)); this._onLiMouseOut.bind(this));
this.createMenu (res, sectionMap, formId, submenu); this.createMenu(res, sectionMap, formId, submenu);
} }
} }
} }
,_onLiMouseHover: function (submenu, parent) ,_onLiMouseHover: function(submenu, parent) {
{
if (this.menuShown) if (this.menuShown)
return; return;
this.hideSubmenu (); this.hideSubmenu();
this.activeSubmenu = submenu; this.activeSubmenu = submenu;
var rect = parent.getBoundingClientRect (); var rect = parent.getBoundingClientRect();
Vn.Node.addClass (submenu, 'popup'); Vn.Node.addClass(submenu, 'popup');
submenu.style.left = rect.right +'px'; submenu.style.left = rect.right +'px';
submenu.style.top = rect.top +'px'; submenu.style.top = rect.top +'px';
} }
,_onLiMouseOut: function () ,_onLiMouseOut: function() {
{ this.timeout = setTimeout(this.hideSubmenu.bind(this), 160);
this.timeout = setTimeout (this.hideSubmenu.bind (this), 160);
} }
,hideSubmenu: function () ,hideSubmenu: function() {
{
var submenu = this.activeSubmenu; var submenu = this.activeSubmenu;
if (submenu) if (submenu) {
{ Vn.Node.removeClass(submenu, 'popup');
Vn.Node.removeClass (submenu, 'popup');
submenu.style.left = ''; submenu.style.left = '';
submenu.style.top = ''; submenu.style.top = '';
clearTimeout (this.timeout); clearTimeout(this.timeout);
this.activeSubmenu = null; this.activeSubmenu = null;
this.timeout = 0; this.timeout = 0;
} }
} }
,showMenu: function () ,showMenu: function() {
{ this.showBackground();
this.showBackground (); Vn.Node.addClass(this.$('left-panel'), 'show');
Vn.Node.addClass (this.$('left-panel'), 'show');
this.menuShown = true; this.menuShown = true;
this.hideMenuCallback = this.hideMenu.bind (this); this.hideMenuCallback = this.hideMenu.bind(this);
this.doc.addEventListener ('click', this.hideMenuCallback); this.doc.addEventListener('click', this.hideMenuCallback);
} }
,hideMenu: function () ,hideMenu: function() {
{
if (!this.menuShown) if (!this.menuShown)
return; return;
this.hideBackground (); this.hideBackground();
Vn.Node.removeClass (this.$('left-panel'), 'show'); Vn.Node.removeClass(this.$('left-panel'), 'show');
this.menuShown = false; this.menuShown = false;
this.doc.removeEventListener ('click', this.hideMenuCallback); this.doc.removeEventListener('click', this.hideMenuCallback);
this.hideMenuCallback = null; this.hideMenuCallback = null;
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Navigation bar //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Navigation bar
,_onScroll: function () ,_onScroll: function() {
{
if (this._scrollTimeout === null) if (this._scrollTimeout === null)
this._scrollTimeout = setTimeout ( this._scrollTimeout = setTimeout(
this._scrollTimeoutFunc.bind (this), 150); this._scrollTimeoutFunc.bind(this), 150);
} }
,_scrollTimeoutFunc: function () ,_scrollTimeoutFunc: function() {
{
if (!this._shown) if (!this._shown)
return; return;
var navbar = this.$('top-bar'); var navbar = this.$('top-bar');
var yOffset = Vn.Browser.getPageYOffset (); var yOffset = Vn.Browser.getPageYOffset();
var showNavbar = this._lastYOffset > yOffset || yOffset < navbar.offsetHeight; var showNavbar = this._lastYOffset > yOffset || yOffset < navbar.offsetHeight;
if (showNavbar !== this._navbarVisible) if (showNavbar !== this._navbarVisible) {
{
if (showNavbar) if (showNavbar)
var translateY = 0; var translateY = 0;
else else
@ -358,227 +319,199 @@ module.exports = new Class
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Background //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Background
,showBackground: function () ,showBackground: function() {
{ Vn.Node.addClass(this.$('background'), 'show');
Vn.Node.addClass (this.$('background'), 'show');
} }
,hideBackground: function () ,hideBackground: function() {
{ Vn.Node.removeClass(this.$('background'), 'show');
Vn.Node.removeClass (this.$('background'), 'show');
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Spinner //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Spinner
,loaderPush: function () ,loaderPush: function() {
{
this.loadingCount++; this.loadingCount++;
if (this.loadingCount == 1) if (this.loadingCount == 1)
this.$('loader').start (); this.$('loader').start();
} }
,loaderPop: function () ,loaderPop: function() {
{
if (this.loadingCount == 0) if (this.loadingCount == 0)
return; return;
this.loadingCount--; this.loadingCount--;
if (this.loadingCount == 0) if (this.loadingCount == 0)
this.$('loader').stop (); this.$('loader').stop();
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Forms //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Forms
,_onFormChange: function () ,_onFormChange: function() {
{
var formPath = this.formParam.value; var formPath = this.formParam.value;
if (!formPath) if (!formPath)
formPath = Vn.Config.defaultForm; formPath = Vn.Config.defaultForm;
this.openForm (formPath, this.openForm(formPath,
this._onFormLoad.bind (this)); this._onFormLoad.bind(this));
} }
,openForm: function (formPath, callback) ,openForm: function(formPath, callback) {
{ this.hideMenu();
this.hideMenu (); this.loaderPush();
this.loaderPush ();
this.closeForm (); this.closeForm();
this.requestedForm = formPath; this.requestedForm = formPath;
var newChoosedOption = this.menuOptions[formPath]; var newChoosedOption = this.menuOptions[formPath];
if (newChoosedOption) if (newChoosedOption) {
{ Vn.Node.addClass(newChoosedOption, 'selected');
Vn.Node.addClass (newChoosedOption, 'selected');
this.choosedOption = newChoosedOption; this.choosedOption = newChoosedOption;
} }
this.activeCss = 'forms/'+ formPath +'/style.css'; this.activeCss = 'forms/'+ formPath +'/style.css';
Vn.includeCss (this.activeCss); Vn.includeCss(this.activeCss);
var formInfo = this.forms[formPath]; var formInfo = this.forms[formPath];
if (!formInfo) if (!formInfo) {
{ formInfo = new Module('forms', formPath);
formInfo = new Module ('forms', formPath);
this.forms[formPath] = formInfo; this.forms[formPath] = formInfo;
} }
formInfo.addCallback (callback); formInfo.addCallback(callback);
} }
,_onFormLoad: function (formInfo) ,_onFormLoad: function(formInfo) {
{ this.loaderPop();
this.loaderPop ();
if (formInfo.error) if (formInfo.error)
{ return Htk.Toast.showError(_('Error loading form'));
Htk.Toast.showError (_('Error loading form')); if (!this._shown)
return; return;
}
this.activeForm = new formInfo.klass (this, formInfo); this.activeForm = new formInfo.klass(this, formInfo);
this.activeForm.open (); this.activeForm.open();
} }
,setForm: function (form) ,setForm: function(form) {
{ Vn.Node.removeChilds(this.$('form-holder'));
Vn.Node.removeChilds (this.$('form-holder'));
if (form) if (form) {
{ this.$('form-holder').appendChild(form);
this.$('form-holder').appendChild (form); setTimeout(this._onSetFormTimeout.bind(this), 0);
setTimeout (this._onSetFormTimeout.bind (this), 0);
} }
} }
,_onSetFormTimeout: function () ,_onSetFormTimeout: function() {
{ Vn.Node.addClass(this.$('form-holder'), 'show');
Vn.Node.addClass (this.$('form-holder'), 'show');
} }
,setTitle: function (title) ,setTitle: function(title) {
{ Vn.Node.removeChilds(this.$('title'));
Vn.Node.removeChilds (this.$('title'));
if (title) if (title)
this.$('title').appendChild (title); this.$('title').appendChild(title);
} }
,setActions: function (actions) ,setActions: function(actions) {
{ Vn.Node.removeChilds(this.$('action-bar'));
Vn.Node.removeChilds (this.$('action-bar'));
if (actions) if (actions)
this.$('action-bar').appendChild (actions); this.$('action-bar').appendChild(actions);
} }
,closeForm: function () ,closeForm: function() {
{ if (this.activeForm) {
if (this.activeForm) Vn.Node.removeClass(this.$('form-holder'), 'show');
{ this.activeForm.close();
Vn.Node.removeClass (this.$('form-holder'), 'show'); this.activeForm.unref();
this.activeForm.close ();
this.activeForm.unref ();
this.activeForm = null; this.activeForm = null;
} }
if (this.activeCss) if (this.activeCss) {
{ Vn.excludeCss(this.activeCss);
Vn.excludeCss (this.activeCss);
this.activeCss = null; this.activeCss = null;
} }
if (this.choosedOption) if (this.choosedOption) {
{ Vn.Node.removeClass(this.choosedOption, 'selected');
Vn.Node.removeClass (this.choosedOption, 'selected');
this.choosedOption = null; this.choosedOption = null;
} }
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Reports //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Reports
,openReport: function (reportName, batch) ,openReport: function(reportName, batch) {
{ this.loaderPush();
this.loaderPush ();
var module = new Module ('reports', reportName); var module = new Module('reports', reportName);
module.addCallback (this._onReportLoad.bind (this, batch)); module.addCallback(this._onReportLoad.bind(this, batch));
} }
,_onReportLoad: function (batch, module) ,_onReportLoad: function(batch, module) {
{ this.loaderPop();
this.loaderPop ();
if (module.error) if (module.error) {
{ Htk.Toast.showError(_('Error loading report'));
Htk.Toast.showError (_('Error loading report'));
return; return;
} }
var report = new module.klass (module, this); var report = new module.klass(module, this);
report.open (batch); report.open(batch);
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Supplant //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Supplant
,supplantInit: function () ,supplantInit: function() {
{ var user = sessionStorage.getItem('supplantUser');
var user = sessionStorage.getItem ('supplantUser');
if (user != null) if (user != null)
this.supplantUser (user); this.supplantUser(user);
} }
,supplantUser: function (user, callback) ,supplantUser: function(user, callback) {
{ this._conn.supplantUser(user,
this._conn.supplantUser (user, this._onUserSupplant.bind(this, callback, user));
this._onUserSupplant.bind (this, callback, user));
} }
,_onUserSupplant: function (callback, user, supplantOk) ,_onUserSupplant: function(callback, user, supplantOk) {
{
if (!supplantOk) if (!supplantOk)
return; return;
sessionStorage.setItem ('supplantUser', user); sessionStorage.setItem('supplantUser', user);
this.loadMenu (); this.loadMenu();
var sql = 'SELECT nickname FROM account.myUser'; var sql = 'SELECT nickname FROM account.myUser';
this._conn.execQuery (sql, this._onSupplantName.bind (this)); this._conn.execQuery(sql, this._onSupplantName.bind(this));
if (callback) if (callback)
callback (); callback();
} }
,_onSupplantName: function (resultSet) ,_onSupplantName: function(resultSet) {
{ var userName = resultSet.fetchValue();
var userName = resultSet.fetchValue (); Vn.Node.setText(this.$('supplanted'), userName);
Vn.Node.setText (this.$('supplanted'), userName); Vn.Node.show(this.$('supplant'));
Vn.Node.show (this.$('supplant'));
} }
,onSupplantExitClick: function () ,onSupplantExitClick: function() {
{ Vn.Node.hide(this.$('supplant'));
Vn.Node.hide (this.$('supplant')); this._conn.supplantEnd();
this._conn.supplantEnd (); sessionStorage.removeItem('supplantUser',
sessionStorage.removeItem ('supplantUser', sessionStorage.getItem('supplantUser'));
sessionStorage.getItem ('supplantUser')); this.loadMenu();
this.loadMenu (); this._onFormChange();
this._onFormChange ();
} }
//++++++++++++++++++++++++++++++++++++++++++++++++++++++ Destroy //++++++++++++++++++++++++++++++++++++++++++++++++++++++ Destroy
,_destroy: function () ,_destroy: function() {
{ this.hide();
this.hide (); this.parent();
this.parent ();
} }
}); });

View File

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