From 40831717f18327673a1f84db7430cb1de7ad30d1 Mon Sep 17 00:00:00 2001 From: Catouse Date: Fri, 29 Apr 2016 10:13:46 +0800 Subject: [PATCH] * refactor code for tutorial mode. --- module/tutorial/control.php | 52 +++++++++++++++++++---------- module/tutorial/lang/en.php | 1 + module/tutorial/lang/zh-cn.php | 1 + module/tutorial/view/index.html.php | 4 +-- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/module/tutorial/control.php b/module/tutorial/control.php index 6c9190b9e8..c7c480c2b6 100644 --- a/module/tutorial/control.php +++ b/module/tutorial/control.php @@ -29,21 +29,8 @@ class tutorial extends control */ public function index($referer = '', $task = '') { - if($_POST) - { - $account = $this->app->user->account; - $setting = $_POST['finish']; - - $this->loadModel('setting')->setItem("$account.tutorial.tasks.setting", $setting); - $this->send(array('result' => 'success')); - } $setting = isset($this->config->tutorial->tasks->setting) ? $this->config->tutorial->tasks->setting : ''; - if($this->viewType === 'json') - { - die(json_encode(array('result' => isset($setting) ? 'success' : 'fail', 'setting' => $setting), JSON_HEX_QUOT | JSON_HEX_APOS)); - } - $this->session->set('tutorialMode', true); $this->view->title = $this->lang->tutorial->common; @@ -54,7 +41,27 @@ class tutorial extends control } /** - * Exit tuturial mode + * Ajax set tasks + * + * @param string $finish + * @access public + * @return void + */ + public function ajaxSetTasks($finish = 'keepAll') + { + if($_POST && isset($_POST['finish'])) $finish = $_POST['finish']; + + if($finish == 'keepAll') $this->send(array('result' => 'fail', 'message' => $this->lang->tutorial->ajaxSetError)); + + $account = $this->app->user->account; + $this->loadModel('setting')->setItem("$account.tutorial.tasks.setting", $finish); + $this->send(array('result' => 'success')); + } + + /** + * Exit tutorial mode + * + * @param string $referer * @access public * @return void */ @@ -62,10 +69,19 @@ class tutorial extends control { $this->session->set('tutorialMode', false); - if(!empty($referer)) - { - die(js::locate($this->createLink('index'), 'parent')); - } + if(empty($referer)) $referer = $this->createLink('index'); + die(js::locate($referer, 'parent')); + } + + /** + * Ajax quit tutorial mode + * + * @access public + * @return void + */ + public function ajaxQuit() + { + $this->session->set('tutorialMode', false); die(json_encode(array('result' => 'success'))); } diff --git a/module/tutorial/lang/en.php b/module/tutorial/lang/en.php index 3f948ac38a..6af50c8ab4 100644 --- a/module/tutorial/lang/en.php +++ b/module/tutorial/lang/en.php @@ -29,6 +29,7 @@ $lang->tutorial->targetPageTip = 'Open【%s】page by this instruction'; $lang->tutorial->requiredTip = '【%s】is necessary'; $lang->tutorial->congratulateTask = 'Congratulations!You have finished task【】!'; $lang->tutorial->serverErrorTip = 'Some error has occurred.'; +$lang->tutorial->ajaxSetError = 'Finished task must be defined. Set empty value to reset tasks.'; $lang->tutorial->tasks = array(); diff --git a/module/tutorial/lang/zh-cn.php b/module/tutorial/lang/zh-cn.php index fc0292a318..b236768e98 100644 --- a/module/tutorial/lang/zh-cn.php +++ b/module/tutorial/lang/zh-cn.php @@ -29,6 +29,7 @@ $lang->tutorial->targetPageTip = '按此指示打开【%s】页面'; $lang->tutorial->requiredTip = '【%s】为必填项'; $lang->tutorial->congratulateTask = '恭喜,你完成了任务 【】!'; $lang->tutorial->serverErrorTip = '发生了一些错误。'; +$lang->tutorial->ajaxSetError = '必须指定已完成的任务,如果要重置任务,请设置值为空。'; $lang->tutorial->tasks = array(); diff --git a/module/tutorial/view/index.html.php b/module/tutorial/view/index.html.php index 7161753c9a..46bfb571c9 100644 --- a/module/tutorial/view/index.html.php +++ b/module/tutorial/view/index.html.php @@ -167,7 +167,7 @@ $(function() var postData = []; $.each(setting, function(name, value) {if(value) postData.push(name);}); - $.post('', {finish: postData.join(',')}, function(e) + $.post('', {finish: postData.join(',')}, function(e) { if(e.result === 'success') { @@ -186,7 +186,7 @@ $(function() var resetTasks = function() { - $.post('', {finish: ''}, function(e) + $.post('', {finish: ''}, function(e) { if(e.result === 'success') {