From a472c51a09f3b4297c5918295b848db35327abb4 Mon Sep 17 00:00:00 2001 From: rylon Date: Fri, 23 Jan 2015 15:54:41 +0100 Subject: [PATCH] statesystem improvement working pretty good now ;-) including variables for calls --- api/api_system.php | 4 +- dbd/qq/SYS_PAGE_GROUP.php | 2 + dbd/sql/mysql/data/sai_api.sql | 7 +- dbd/sql/mysql/data/system_api.sql | 1 + dbd/sql/mysql/schema/system_page.sql | 5 +- files/sys/system.js | 96 ++++++++++++---------------- page/State.php | 16 +++-- 7 files changed, 62 insertions(+), 69 deletions(-) diff --git a/api/api_system.php b/api/api_system.php index b8efcf7..832ca95 100644 --- a/api/api_system.php +++ b/api/api_system.php @@ -12,8 +12,8 @@ class api_system extends api_login{ public static function call_files($cat,$id = null){ return \SYSTEM\FILES\files::get($cat, $id, true);} - public static function call_pages($group){ - return \SYSTEM\PAGE\State::get($group);} + public static function call_pages($group,$state){ + return \SYSTEM\PAGE\State::get($group,$state);} public static function static__lang($lang){ \SYSTEM\locale::set($lang);} diff --git a/dbd/qq/SYS_PAGE_GROUP.php b/dbd/qq/SYS_PAGE_GROUP.php index e51fa42..89af6ca 100644 --- a/dbd/qq/SYS_PAGE_GROUP.php +++ b/dbd/qq/SYS_PAGE_GROUP.php @@ -7,9 +7,11 @@ class SYS_PAGE_GROUP extends \SYSTEM\DB\QP { //pg 'SELECT * FROM '.\SYSTEM\DBD\system_page::NAME_PG .' WHERE "'.\SYSTEM\DBD\system_page::FIELD_GROUP.'" = $1' +.' AND "'.\SYSTEM\DBD\system_page::FIELD_ID.'" = $2' .' ORDER BY "'.\SYSTEM\DBD\system_page::FIELD_ID.'"', //mys 'SELECT * FROM '.\SYSTEM\DBD\system_page::NAME_MYS .' WHERE `'.\SYSTEM\DBD\system_page::FIELD_GROUP.'` = ?' +.' AND `'.\SYSTEM\DBD\system_page::FIELD_ID.'` = ?' .' ORDER BY '.\SYSTEM\DBD\system_page::FIELD_ID );}} \ No newline at end of file diff --git a/dbd/sql/mysql/data/sai_api.sql b/dbd/sql/mysql/data/sai_api.sql index 475d095..4745657 100644 --- a/dbd/sql/mysql/data/sai_api.sql +++ b/dbd/sql/mysql/data/sai_api.sql @@ -21,9 +21,10 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (31, 42, 3, 30, 'files', 'id', 'STRING'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (40, 42, 2, 10, 'text', 'request', 'STRING'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (41, 42, 2, 40, 'text', 'lang', 'LANG'); -INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 42, 2, 10, 'pagestates', 'group', 'UINT'); -INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (51, 42, 1, 50, NULL, 'js', NULL); -INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (52, 42, 2, 51, NULL, 'group', 'UINT'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 42, 2, 10, 'pages', 'group', 'UINT'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (51, 42, 2, 10, 'pages', 'state', 'STRING'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (52, 42, 1, 50, NULL, 'js', NULL); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (53, 42, 2, 51, NULL, 'group', 'UINT'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (55, 42, 1, 50, NULL, 'css', NULL); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (56, 42, 2, 55, NULL, 'group', 'UINT'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (90, 42, 4, -1, NULL, '_lang', 'LANG'); diff --git a/dbd/sql/mysql/data/system_api.sql b/dbd/sql/mysql/data/system_api.sql index a459ff5..8c1bf33 100644 --- a/dbd/sql/mysql/data/system_api.sql +++ b/dbd/sql/mysql/data/system_api.sql @@ -19,6 +19,7 @@ INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `nam INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (41, 0, 2, 10, 'text', 'lang', 'LANG'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (50, 0, 2, 10, 'pages', 'group', 'UINT'); +INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (51, 0, 2, 10, 'pages', 'state', 'STRING'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (90, 0, 4, -1, NULL, '_lang', 'LANG'); INSERT INTO `system_api` (`ID`, `group`, `type`, `parentID`, `parentValue`, `name`, `verify`) VALUES (91, 0, 4, -1, NULL, '_result', 'RESULT'); \ No newline at end of file diff --git a/dbd/sql/mysql/schema/system_page.sql b/dbd/sql/mysql/schema/system_page.sql index 78d506c..871cd6b 100644 --- a/dbd/sql/mysql/schema/system_page.sql +++ b/dbd/sql/mysql/schema/system_page.sql @@ -4,7 +4,8 @@ CREATE TABLE `system_page` ( `div` CHAR(50) NOT NULL, `url` TEXT NOT NULL, `func` CHAR(50) NOT NULL, + `php_class` CHAR(50) NOT NULL, PRIMARY KEY (`id`, `div`, `group`) ) -COLLATE='utf8_general_ci' -ENGINE=InnoDB; \ No newline at end of file +COLLATE='utf8_unicode_ci' +ENGINE=InnoDB; diff --git a/files/sys/system.js b/files/sys/system.js index 2098fc0..6761e8f 100644 --- a/files/sys/system.js +++ b/files/sys/system.js @@ -15,14 +15,48 @@ function SYSTEM(endpoint, group,start_state){ this.go_state(start_state); } //internal function to handle pagestate results -SYSTEM.prototype.handle_call_pages = function (data) { +SYSTEM.prototype.handle_call_pages = function (data,id) { if(data['status']){ - newps = data['result']; - system.log(system.LOG_INFO,'load pages: '+system.endpoint+':'+system.group+' - success'); - result = true; + system.log(system.LOG_INFO,'load pages: endpoint '+system.endpoint+':group '+system.group+':state '+id+' - success'); + window.history.pushState(null, "", '#'+id); + data['result'].forEach(function(entry) { + //load pages + $.ajax({ + async: false, + data: {}, + dataType: 'html', + url: entry['url']+'&'+window.location.search.substr(1), + success: function(data){ + $(entry['div']).html(data); + system.log(system.LOG_INFO,'load page: '+id+entry['div']+' '+entry['url']+'&'+window.location.search.substr(1)+' - success');}, + error: function(XMLHttpRequest, textStatus, errorThrown){system.log(system.LOG_ERROR,errorThrown);} + }); + //load css + for(var i=0; i < entry['css'].length; i++){ + system.load_css(entry['css'][i]);} + //load js + var call_func = true; + var loaded = 0; + for(var i=0; i < entry['js'].length; i++){ + system.log(system.LOG_INFO,'load js: '+entry['js'][i]); + $.getScript(entry['js'][i]).done(function(response, status) { + system.log(system.LOG_INFO,'load js: '+status); + if(loaded++ == entry['js'].length-1){ + var fn = window[entry['func']]; + if(call_func && typeof fn === 'function'){ + call_func = false; + fn(); + system.log(system.LOG_INFO,'call func: '+entry['func']); + } else { + system.log(system.LOG_ERROR,'call func: '+entry['func']+' - fail'); + }} + }); + } + }); } else { + console.log(data); system.log(system.LOG_INFO,'Problem with your Pages: '+data['result']['message']); - result = false;} + } }; //send a call to the endpoint SYSTEM.prototype.call = function(call,success,data,data_type,async){ @@ -63,57 +97,7 @@ SYSTEM.prototype.load_page = function(){ //load a pagestatewith given id SYSTEM.prototype.load = function(id){ system.log(system.LOG_START,'load page '+id); - if(!system.load_page()){ - system.log(system.LOG_ERROR,'Problem with your Pages'); - return false;} - var push = true; - var found = false; - system.pages.forEach(function(entry) { - if(entry['id'] === id){ - found = true; - //write new state - if(push){ - window.history.pushState(null, "", '#'+id); - push = false;} - //load pages - $.ajax({ - async: false, - data: {}, - dataType: 'html', - url: entry['url']+'&'+window.location.search.substr(1), - success: function(data){ - $(entry['div']).html(data); - system.log(system.LOG_INFO,'load page: '+id+entry['div']+' '+entry['url']+'&'+window.location.search.substr(1)+' - success');}, - error: function(XMLHttpRequest, textStatus, errorThrown){system.log(system.LOG_ERROR,errorThrown);} - }); - //load css - for(var i=0; i < entry['css'].length; i++){ - system.load_css(entry['css'][i]);} - //load js - var call_func = true; - var loaded = 0; - for(var i=0; i < entry['js'].length; i++){ - system.log(system.LOG_INFO,'load js: '+entry['js'][i]); - $.getScript(entry['js'][i]).done(function(response, status) { - system.log(system.LOG_INFO,'load js: '+status); - if(loaded++ == entry['js'].length-1){ - var fn = window[entry['func']]; - if(call_func && typeof fn === 'function'){ - call_func = false; - fn(); - system.log(system.LOG_INFO,'call func: '+entry['func']); - } else { - system.log(system.LOG_ERROR,'call func: '+entry['func']+' - fail'); - }} - }); - } - } - }); - if(!found){ - window.history.pushState(null, "", '#'); - window.location.reload();} - return push ? false : true; -}; + this.call('call=pages&group='+this.group+'&state='+id,function(data){system.handle_call_pages(data,id);},{},"json",false);}; SYSTEM.prototype.load_css = function loadCSS(csssrc) { var snode = document.createElement('link'); diff --git a/page/State.php b/page/State.php index a981505..9888db2 100644 --- a/page/State.php +++ b/page/State.php @@ -1,16 +1,20 @@ next()){ + $row['url'] = \SYSTEM\PAGE\replace::replace($row['url'], $vars); $row['css'] = $row['js'] = array(); - if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ + if(/*\is_callable($row['php_class']) &&*/ \class_exists($row['php_class']) && \method_exists($row['php_class'], 'css') && \is_callable($row['php_class'].'::css')){ $row['css'] = array_merge($row['css'], call_user_func($row['php_class'].'::css'));} - if(\class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){ + if(/*\is_callable($row['php_class']) &&*/ \class_exists($row['php_class']) && \method_exists($row['php_class'], 'js') && \is_callable($row['php_class'].'::js')){ $row['js'] = array_merge($row['js'], call_user_func($row['php_class'].'::js'));} $result[] = $row;} return \SYSTEM\LOG\JsonResult::toString($result);}