From 36c76bb1b3a1b5d90c5428ebc8580902440b6914 Mon Sep 17 00:00:00 2001 From: rylon Date: Fri, 10 Apr 2015 03:29:27 +0200 Subject: [PATCH] system statesystem for todo and log --- files/sys/system.js | 16 +- .../saimod_sys_log/tpl/saimod_sys_log.tpl | 2 +- .../tpl/saimod_sys_log_table_row.tpl | 2 +- .../saimod_sys_todo/js/saimod_sys_todo.js | 141 ++++++------------ .../saimod_sys_todo/saimod_sys_todo.php | 3 + .../saimod_sys_todo/tpl/saimod_sys_todo.tpl | 10 +- .../tpl/saimod_sys_todo_new.tpl | 2 +- .../tpl/saimod_sys_todo_todo.tpl | 2 +- .../tpl/saimod_sys_todo_todo_user.tpl | 2 +- .../tpl/todo_user_list_element.tpl | 2 +- 10 files changed, 69 insertions(+), 113 deletions(-) diff --git a/files/sys/system.js b/files/sys/system.js index b2a1672..183ad84 100644 --- a/files/sys/system.js +++ b/files/sys/system.js @@ -47,21 +47,23 @@ SYSTEM.prototype.handle_call_pages_page = function (html,entry,id,forced,cached) $.getScript(entry['js'][i]) .done(function(response, status, jqxhr) { system.log_info('load js: '+status); + system.state_js[entry['js'][i]] = true; if(loaded++ === entry['js'].length-1){ var fn = window[entry['func']]; - if(call_func && typeof fn === 'function'){ - call_func = false; - fn(); - system.log_info('call func: '+entry['func']); - } else { - system.log_error('call func: '+entry['func']+' - fail'); + if(call_func ){ + if(typeof fn === 'function'){ + call_func = false; + fn(); + system.log_info('call func: '+entry['func']); + } else { + system.log_error('call func: '+entry['func']+' - fail'); + } } } }) .fail(function( jqxhr, settings, exception ) { system.log_error( "Something went wrong"+exception ); }); - this.state_js[entry['js'][i]] = true; } else { this.log_info('load js: '+entry['js'][i]+' - cached'); if(loaded++ === entry['js'].length-1){ diff --git a/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl b/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl index 9fc571c..d30a8e6 100644 --- a/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl +++ b/sai/modules/saimod_sys_log/tpl/saimod_sys_log.tpl @@ -5,7 +5,7 @@
  • Log
  • Statistics
  • - +
    diff --git a/sai/modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl b/sai/modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl index 884092a..ad525d7 100644 --- a/sai/modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl +++ b/sai/modules/saimod_sys_log/tpl/saimod_sys_log_table_row.tpl @@ -1,4 +1,4 @@ - + ${time} ${class} ${message} diff --git a/sai/modules/saimod_sys_todo/js/saimod_sys_todo.js b/sai/modules/saimod_sys_todo/js/saimod_sys_todo.js index cbf1d7f..bc23549 100644 --- a/sai/modules/saimod_sys_todo/js/saimod_sys_todo.js +++ b/sai/modules/saimod_sys_todo/js/saimod_sys_todo.js @@ -1,46 +1,69 @@ -function init_saimod_sys_todo() { +function init_saimod_sys_todo() { $('#tabs_todo a').click(function (e) { - e.preventDefault(); - $(this).tab('show'); - load_todo_tab($(this).attr('action')); + $('#tabs_todo li').each(function(){ + $(this).removeClass('active');}); + $(this).parent().addClass('active'); }); - - load_todo_tab('todolist'); - register_new(); + if(system.cur_state() === 'todo(stats)'){ + $('#tabs_todo li').each(function(){ + $(this).removeClass('active');}); + $('#menu_stats').parent().addClass('active'); + } + if(system.cur_state() === 'todo(doto)'){ + $('#tabs_todo li').each(function(){ + $(this).removeClass('active');}); + $('#menu_doto').parent().addClass('active'); + } + + $('#btn_close_all').click(function(){ + if (confirm('Are you sure you want to delete all open entries in the todolist?')) { + $.ajax({ type :'GET', + url : './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=close_all', + success : function(data) { + if(data.status){ + system.load('todo'); + }else{ + alert('Problem: '+data);} + } + }); + } + }) }; -function register_new(){ - $('#btn_new').click(function(){ - $('#img_loader').show(); - $('#tab_todo').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=new', function(){ - register_newform(); - $('#btn_back').click(function(){ - load_todo_tab('todolist');}); - $('#img_loader').hide(); - }); - }); -} - -function register_edit(){ +function init_saimod_sys_todo_todoopen(){ $('#btn_edit').click(function(){ $.ajax({ type : 'GET', url : './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=edit&todo='+$(this).attr('todo')+'&message='+encodeURIComponent($('#ta_message').val()), success : function(data) { if(data.status){ - load_todo_tab('todolist'); + system.load('todo'); } } }); }); + register_open(); +} +function init_saimod_sys_todo_todoclose(){ + $('#btn_edit').click(function(){ + $.ajax({ type : 'GET', + url : './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=edit&todo='+$(this).attr('todo')+'&message='+encodeURIComponent($('#ta_message').val()), + success : function(data) { + if(data.status){ + system.load('todo'); + } + } + }); + }); + register_close(); } -function register_newform(){ +function init_saimod_sys_todo_new(){ $('#btn_add').click(function(){ $.ajax({ type : 'GET', url : './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=add&todo='+encodeURIComponent($('#input_message').val()), success : function(data) { if(data.status){ - load_todo_tab('todolist'); + system.load('todo'); } } }); @@ -48,42 +71,6 @@ function register_newform(){ $('#input_message').focus(); } -function load_todo_tab(action){ - $('#img_loader').show(); - switch(action){ - case 'todolist': - $('#tab_todo').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action='+action, function(){ - register_todolist(); - register_listclick(true); - $('#img_loader').hide();}); - return; - case 'dotolist': - $('#tab_todo').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action='+action, function(){ - register_doto(); - register_listclick(); - $('#img_loader').hide();}); - return; - case 'stats': - $('#tab_todo').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action='+action, function(){ - register_stats(); - $('#img_loader').hide();}); - return; - default: - $('#img_loader').hide(); - } -} - -function register_listclick(todo){ - $('.sai_todo_element').click(function(){ - $('#img_loader').show(); - $('#tab_todo').load('./sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=todo&todo='+$(this).attr('todo'), function(){ - register_edit(); - $('#btn_back').click(function(){ - if(todo){load_todo_tab('todolist');}else{load_todo_tab('dotolist');}}); - if(todo){register_close();}else{register_open();} - $('#img_loader').hide();})}); -} - function register_open(){ $('#btn_open').show(); $('#btn_open').click(function(){ @@ -113,39 +100,3 @@ function register_close(){ }); }); } - -function register_todolist(){ - $('#btn_refresh').unbind('click'); - $('#btn_refresh').click(function(){ - load_todo_tab('todolist');}); - $('#btn_close_all').unbind('click'); - $('#btn_close_all').click(function(){ - if (confirm('Are you sure you want to delete all open entries in the todolist?')) { - $.ajax({ type :'GET', - url : './sai.php?sai_mod=.SYSTEM.SAI.saimod_sys_todo&action=close_all', - success : function(data) { - if(data.status){ - load_todo_tab('todolist'); - }else{ - alert('Problem: '+data);} - } - }); - } - }) -} -function register_doto(){ - $('#btn_refresh').unbind('click'); - $('#btn_refresh').click(function(){ - load_todo_tab('dotolist');}); - $('#btn_close_all').unbind('click'); - $('#btn_close_all').click(function(){ - alert('operation not possible on this list');}); -} -function register_stats(){ - $('#btn_refresh').unbind('click'); - $('#btn_refresh').click(function(){ - load_todo_tab('stats');}); - $('#btn_close_all').unbind('click'); - $('#btn_close_all').click(function(){ - alert('operation not possible on this list');}); -} \ No newline at end of file diff --git a/sai/modules/saimod_sys_todo/saimod_sys_todo.php b/sai/modules/saimod_sys_todo/saimod_sys_todo.php index e6b2d7f..f42b421 100644 --- a/sai/modules/saimod_sys_todo/saimod_sys_todo.php +++ b/sai/modules/saimod_sys_todo/saimod_sys_todo.php @@ -49,6 +49,7 @@ class saimod_sys_todo extends \SYSTEM\SAI\SaiModule { $row['state_btn'] = self::statebtn($row['count']); $row['message'] = htmlspecialchars($row['message']); $row['request_uri'] = htmlspecialchars($row['request_uri']); + $row['openclose'] = 'close'; if($row['type'] == \SYSTEM\DBD\system_todo::FIELD_TYPE_USER){ $row['message'] = str_replace("\r", '
    ', $row['message']); $result_user .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_todo/tpl/todo_user_list_element.tpl'), $row); @@ -67,6 +68,8 @@ class saimod_sys_todo extends \SYSTEM\SAI\SaiModule { $row['time_elapsed'] = self::time_elapsed_string(strtotime($row['time'])); $row['state_string'] = self::state($row['count']); $row['state_btn'] = self::statebtn($row['count']); + $row['request_uri'] = htmlspecialchars($row['request_uri']); + $row['openclose'] = 'open'; if($row['type'] == \SYSTEM\DBD\system_todo::FIELD_TYPE_USER){ $row['message'] = str_replace("\r", '
    ', $row['message']); $result_user .= \SYSTEM\PAGE\replace::replaceFile(\SYSTEM\SERVERPATH(new \SYSTEM\PSAI(),'modules/saimod_sys_todo/tpl/todo_user_list_element.tpl'), $row); diff --git a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo.tpl b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo.tpl index f2d4bae..640c1d4 100644 --- a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo.tpl +++ b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo.tpl @@ -2,13 +2,13 @@
    diff --git a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_new.tpl b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_new.tpl index f122f54..c463488 100644 --- a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_new.tpl +++ b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_new.tpl @@ -1,5 +1,5 @@
    Message
    - + \ No newline at end of file diff --git a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo.tpl b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo.tpl index f688d84..833cb6d 100644 --- a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo.tpl +++ b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo.tpl @@ -21,6 +21,6 @@ thrown${thrown} message${message} - + \ No newline at end of file diff --git a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo_user.tpl b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo_user.tpl index 21a2e41..05d2a04 100644 --- a/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo_user.tpl +++ b/sai/modules/saimod_sys_todo/tpl/saimod_sys_todo_todo_user.tpl @@ -10,7 +10,7 @@ user${username} message - + \ No newline at end of file diff --git a/sai/modules/saimod_sys_todo/tpl/todo_user_list_element.tpl b/sai/modules/saimod_sys_todo/tpl/todo_user_list_element.tpl index e37d0b7..a52d051 100644 --- a/sai/modules/saimod_sys_todo/tpl/todo_user_list_element.tpl +++ b/sai/modules/saimod_sys_todo/tpl/todo_user_list_element.tpl @@ -1,4 +1,4 @@ - + ${time_elapsed} ${message} ${username}