statesystem improvement working pretty good now ;-) including variables for calls
This commit is contained in:
parent
96078ca1bd
commit
a472c51a09
@ -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);}
|
||||
|
||||
@ -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
|
||||
);}}
|
||||
@ -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');
|
||||
|
||||
@ -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');
|
||||
@ -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;
|
||||
COLLATE='utf8_unicode_ci'
|
||||
ENGINE=InnoDB;
|
||||
|
||||
@ -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');
|
||||
|
||||
@ -1,16 +1,20 @@
|
||||
<?php
|
||||
namespace SYSTEM\PAGE;
|
||||
|
||||
class State {
|
||||
public static function get($group){
|
||||
public static function get($group,$state){
|
||||
$state = \explode(';', $state);
|
||||
$vars = array();
|
||||
for($i=1;$i<count($state);$i++){
|
||||
$var = \explode('.',$state[$i]);
|
||||
$vars[$var[0]] = $var[1];}
|
||||
$result = array();
|
||||
|
||||
$res = \SYSTEM\DBD\SYS_PAGE_GROUP::QQ(array($group));
|
||||
$res = \SYSTEM\DBD\SYS_PAGE_GROUP::QQ(array($group,$state[0]));
|
||||
while($row = $res->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);}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user