ajax即時任務提示功能的實現代碼第1/2頁_AJAX相關

來源:互聯網
上載者:User
項目代碼結構見 我之前寫的[EXT/FCKEditor 整合 -- AJAX UI -- 一種web開發的新的思維,要及時轉換思想]一文.
中的
├─taskofpig
│ ├─Controller
│ ├─Dao
│ ├─js
│ ├─music
│ ├─tpl
│ ├─tpl_c
│ └─_log
項目代碼如下:
db.sql
SET FOREIGN_KEY_CHECKS=0;
-- ----------------------------
-- Table structure for task
-- ----------------------------
CREATE TABLE `task` (
`id` int(11) NOT NULL,
`title` varchar(100) collate utf8_unicode_ci NOT NULL,
`desc` text collate utf8_unicode_ci,
`date` datetime NOT NULL,
`created` int(11) default NULL,
`updated` int(11) default NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
-- ----------------------------
-- Table structure for task_seq
-- ----------------------------
CREATE TABLE `task_seq` (
`id` int(11) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
/ucren/taskofpig/index.php
<?php
//設定正確的時區
date_default_timezone_set("Asia/Shanghai");
define('TASKOFPIG_DIR',dirname(__FILE__)) ;
require('../phplibs/FLEA/FLEA.php');
// 對$GLOBALS[G_FLEA_VAR]['CLASS_PATH'] 進行配置
FLEA::import(TASKOFPIG_DIR); //將目前的目錄加入到環境變數中
FLEA::loadAppInf('appConfig.php') ; //將設定檔單獨分出來,容易維護
FLEA::init();
// 由於 FLEA_Db_TableDataGateway 並不是自動載入的,因此需要明確載入
FLEA::loadClass('FLEA_Db_TableDataGateway');
FLEA::runMVC();
?>
/ucren/taskofpig/appConfig.php
<?php
// 對 $GLOBALS[G_FLEA_VAR]['APP_INF'] 進行配置
return array(
'dispatcher' => 'FLEA_Dispatcher_Simple' , //定製調度器 FLEA_Dispatcher_Auth
'controllerAccessor' => 'ctl' ,
'actionAccessor' => 'act' ,
'view' => 'FLEA_View_Smarty', //定製視圖
'viewConfig' => array(
'smartyDir' => '../phplibs/Smarty',
'template_dir' => './tpl',
'compile_dir' => './tpl_c',
'left_delimiter' => '<%',
'right_delimiter' => '%>',
'debugging' => false
),
'dbDSN' => array( //定製資料庫連接參數
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'dbuser',
'password' => 'dbpass',
'database' => 'dbname' ,
'charset ' => 'utf8'
) ,
'logFileDir' => './log' , //定製日誌
'logFilename' => 'task_admin.log'
);
?>
/ucren/taskofpig/Dao/Table.php
<?php
//生氣豬的任務計劃表
class Dao_TaskTable extends FLEA_Db_TableDataGateway
{
// 指定資料表名稱
var $tableName = 'task';
// 指定主鍵欄位名
var $primaryKey = 'id';
}
?>
/ucren/taskofpig/Controller/Default.php
<?php
FLEA::loadFile('Dao_Table.php',true) ;
FLEA::loadFile('FLEA_Ajax_JSON.php',true) ;
class Controller_Default extends FLEA_Controller_Action
{
var $smarty ;
function Controller_Default()
{
$this->smarty = $this->_getView();
$this->smarty->assign('sitename','任務計劃表 -- 生氣豬') ;
$this->smarty->assign('opname','工作清單') ;//預設應該在子模組中更改值
}
function actionIndex()
{
$this->toModulePage(); //預設顯示工作清單頁
}
//定義一個函數用於調用FCKeditor
function call_fck($input_name,$input_value,$w='800',$h='400')
{
include_once '../fckeditor/fckeditor.php';
$fcked = new FCKeditor($input_name) ;
$fcked->BasePath = '../fckeditor/';
$fcked->ToolbarSet = 'Default' ; //工具列設定
$fcked->InstanceName = $input_name ;
$fcked->Width = $w;
$fcked->Height = $h;
$fcked->Value = $input_value;
$fck_area = $fcked->CreateHtml();
$this->smarty->assign('fck_area',$fck_area);
unset($fck_area) ;
unset($fcked) ;
}
function _showPage($tpl='taskofpig.main.html')
{
$this->smarty->display($tpl);
}
function actionAdd()
{
$this->addTask();
}
function actionUpdate()
{
$this->updateTask();
}
function deleteTask($id){
$row = array('id'=>$id);
$thisDao = & new Dao_TaskTable() ;
$status = $thisDao->remove($row); //返回boolean值
unset($thisDao);
return $status ;
}
function listTask()
{
$thisDao = & new Dao_TaskTable() ;
$rows = $thisDao->findAll(); //二維數組
foreach($rows as &$row) //注意這裡要傳引用
{
$row['desc'] = mb_substr($row['desc'],0,40,'UTF-8');
}
$this->smarty->assign('rowSet',$rows);
$this->_showPage();
}
function addTask()
{
$thisDao = & new Dao_TaskTable() ;
$row = array(
'title' => $_REQUEST['title'],
'desc' => $_REQUEST['desc'],
'date' => $_REQUEST['date']
);
$commitId = $thisDao->create($row);
unset($thisDao);
echo "成功添加新任務";
redirect( url("Default"),1) ;
}
function updateTask()
{
$thisDao = & new Dao_TaskTable() ;
$row = array(
'id' => $_REQUEST['id'],
'title' => $_REQUEST['title'],
'desc' => $_REQUEST['desc'],
'date' => $_REQUEST['date']
);
$commitId = $thisDao->update($row);
unset($thisDao);
echo "成功更新任務";
redirect( url("Default"),1) ;
}
function queryTask($id){
$thisDao = & new Dao_TaskTable() ;
$row = $thisDao->find(array('id'=>$id));
unset($thisDao);
return $row ;
}
function queryTaskForDate($date=null)
{
$thisDao = & new Dao_TaskTable() ; //'2008-08-17 07:42:29'
$row = $thisDao->find(array('date'=>date('Y-m-d H:i:s')));
unset($thisDao);
if (!empty($row))
{
$jsonobj = new Services_JSON();
echo $jsonobj->encode($row);
}
else
die(date('Y-m-d H:i:s'));
}
//任務流轉控制方法
function toModulePage()
{
if ($_REQUEST['op'] == 'search') {
$this->queryTaskForDate();
}
else if ($_REQUEST['op'] == 'add') {
$this->smarty->assign('opname','添加新任務') ;
$this->smarty->assign('taskTime',date('Y-m-d H:i:s')) ;
$this->call_fck('desc','');
$this->_showPage('taskofpig.add.html');
}
else if ($_REQUEST['op'] == 'del') {
if ( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) )
$status = $this->deleteTask($_REQUEST['id']) ;
$this->listTask();
}
else if ($_REQUEST['op'] == 'edit') {
if ( isset($_REQUEST['id']) && is_numeric($_REQUEST['id']) ){
$row = $this->queryTask($_REQUEST['id']) ;
}
$this->call_fck('desc',$row['desc']);
unset($row['desc']) ;
$this->smarty->assign('rowSet',$row);
$this->smarty->assign('opname','修改任務') ;
$this->_showPage('taskofpig.edit.html');
}
else { //列表
$this->listTask();
}
}
}
?>
當前1/2頁  12下一頁閱讀全文
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.