update Schedule full CRUD

This commit is contained in:
dongpd 2020-10-13 17:31:53 +07:00
parent 03e03c7e13
commit 620dfc75c2
15 changed files with 908 additions and 19 deletions

23
assets/ScheduleAsset.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace app\assets;
use yii\web\AssetBundle;
class ScheduleAsset extends AssetBundle {
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
];
public $js = [
'js/schedule.js'
];
public $depends = [
'yii\web\YiiAsset',
'app\assets\AppAsset',
// 'yii\jui\JuiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

View File

@ -2,5 +2,5 @@
return [
"hideInfomation" => false,
"TCTECH" => false
"TCTECH" => true
];

View File

@ -0,0 +1,157 @@
<?php
namespace app\controllers;
use Yii;
use app\models\Schedule;
use app\models\ScheduleSearch;
use yii\web\Controller;
use yii\web\NotFoundHttpException;
use yii\filters\VerbFilter;
use yii\helpers\Html;
use yii\helpers\Url;
/**
* ScheduleController implements the CRUD actions for Schedule model.
*/
class ScheduleController extends Controller {
public function init() {
parent::init();
if (Yii::$app->user->isGuest)
return $this->redirect(['/site/login']);
}
/**
* {@inheritdoc}
*/
public function behaviors() {
return [
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'delete' => ['POST'],
],
],
];
}
public function actionIndex() {
$this->view->title = 'Lịch trình';
$searchModel = new ScheduleSearch();
$dataProvider = $searchModel->search(Yii::$app->request->queryParams);
return $this->render('index', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}
public function actionCreate() {
$model = new Schedule();
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$data = [
"Name" => $post["Name"],
"Description" => $post["Description"],
"SunTime1" => Schedule::combineTime($post["FromSun1"], $post["ToSun1"]),
"SunTime2" => Schedule::combineTime($post["FromSun2"], $post["ToSun2"]),
"SunTime3" => Schedule::combineTime($post["FromSun3"], $post["ToSun3"]),
"MonTime1" => Schedule::combineTime($post["FromMon1"], $post["ToMon1"]),
"MonTime2" => Schedule::combineTime($post["FromMon2"], $post["ToMon2"]),
"MonTime3" => Schedule::combineTime($post["FromMon3"], $post["ToMon3"]),
"TueTime1" => Schedule::combineTime($post["FromTue1"], $post["ToTue1"]),
"TueTime2" => Schedule::combineTime($post["FromTue2"], $post["ToTue2"]),
"TueTime3" => Schedule::combineTime($post["FromTue3"], $post["ToTue3"]),
"WedTime1" => Schedule::combineTime($post["FromWed1"], $post["ToWed1"]),
"WedTime2" => Schedule::combineTime($post["FromWed2"], $post["ToWed2"]),
"WedTime3" => Schedule::combineTime($post["FromWed3"], $post["ToWed3"]),
"ThuTime1" => Schedule::combineTime($post["FromThu1"], $post["ToThu1"]),
"ThuTime2" => Schedule::combineTime($post["FromThu2"], $post["ToThu2"]),
"ThuTime3" => Schedule::combineTime($post["FromThu3"], $post["ToThu3"]),
"FriTime1" => Schedule::combineTime($post["FromFri1"], $post["ToFri1"]),
"FriTime2" => Schedule::combineTime($post["FromFri2"], $post["ToFri2"]),
"FriTime3" => Schedule::combineTime($post["FromFri3"], $post["ToFri3"]),
"SatTime1" => Schedule::combineTime($post["FromSat1"], $post["ToSat1"]),
"SatTime2" => Schedule::combineTime($post["FromSat2"], $post["ToSat2"]),
"SatTime3" => Schedule::combineTime($post["FromSat3"], $post["ToSat3"])
];
if ($model->create($data)) {
return ["status" => true];
} else
return ["status" => false, "type" => "error"];
} else {
return [
"title" => Html::tag("i", "", ["class" => "fa fa-plus-square"]) . " Thêm",
"form" => $this->renderPartial("form", [
"model" => $model,
"url" => Url::to(["create"]),
"dayOfWeek" => Schedule::$dayOfWeek
])
];
}
}
public function actionUpdate($id) {
$model = $this->findModel($id);
Yii::$app->response->format = "json";
if (Yii::$app->request->post()) {
$post = Yii::$app->request->post();
$model->name = $post["Name"];
$model->description = $post["Description"];
$model->SunTime1 = Schedule::combineTime($post["FromSun1"], $post["ToSun1"]);
$model->SunTime2 = Schedule::combineTime($post["FromSun2"], $post["ToSun2"]);
$model->SunTime3 = Schedule::combineTime($post["FromSun3"], $post["ToSun3"]);
$model->MonTime1 = Schedule::combineTime($post["FromMon1"], $post["ToMon1"]);
$model->MonTime2 = Schedule::combineTime($post["FromMon2"], $post["ToMon2"]);
$model->MonTime3 = Schedule::combineTime($post["FromMon3"], $post["ToMon3"]);
$model->TueTime1 = Schedule::combineTime($post["FromTue1"], $post["ToTue1"]);
$model->TueTime2 = Schedule::combineTime($post["FromTue2"], $post["ToTue2"]);
$model->TueTime3 = Schedule::combineTime($post["FromTue3"], $post["ToTue3"]);
$model->WedTime1 = Schedule::combineTime($post["FromWed1"], $post["ToWed1"]);
$model->WedTime2 = Schedule::combineTime($post["FromWed2"], $post["ToWed2"]);
$model->WedTime3 = Schedule::combineTime($post["FromWed3"], $post["ToWed3"]);
$model->ThuTime1 = Schedule::combineTime($post["FromThu1"], $post["ToThu1"]);
$model->ThuTime2 = Schedule::combineTime($post["FromThu2"], $post["ToThu2"]);
$model->ThuTime3 = Schedule::combineTime($post["FromThu3"], $post["ToThu3"]);
$model->FriTime1 = Schedule::combineTime($post["FromFri1"], $post["ToFri1"]);
$model->FriTime2 = Schedule::combineTime($post["FromFri2"], $post["ToFri2"]);
$model->FriTime3 = Schedule::combineTime($post["FromFri3"], $post["ToFri3"]);
$model->SatTime1 = Schedule::combineTime($post["FromSat1"], $post["ToSat1"]);
$model->SatTime2 = Schedule::combineTime($post["FromSat2"], $post["ToSat2"]);
$model->SatTime3 = Schedule::combineTime($post["FromSat3"], $post["ToSat3"]);
$model->modified_at = time();
if ($model->save()) {
return ["status" => true];
} else
return ["status" => false, "type" => "error"];
} else {
return [
"title" => Html::tag("i", "", ["class" => "fa fa-edit"]) . " Tùy chỉnh",
"form" => $this->renderPartial("form", [
"model" => $model,
"url" => Url::to(["update", "id" => $id]),
"dayOfWeek" => Schedule::$dayOfWeek
])
];
}
}
public function actionDelete() {
if (Yii::$app->request->post()) {
$lists = Yii::$app->request->post("lists");
Schedule::deleteAll(["IN", "id", $lists]);
\app\models\Staff::updateAll(["schedule_id" => 0, ["IN", "id", $lists]]);
}
}
protected function findModel($id) {
if (($model = Schedule::findOne($id)) !== null) {
return $model;
}
throw new NotFoundHttpException('The requested page does not exist.');
}
}

153
models/Schedule.php Normal file
View File

@ -0,0 +1,153 @@
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "schedule".
*
* @property int $id
* @property string $name
* @property string $description
* @property string $SunTime1
* @property string $SunTime2
* @property string $SunTime3
* @property string $MonTime1
* @property string $MonTime2
* @property string $MonTime3
* @property string $TueTime1
* @property string $TueTime2
* @property string $TueTime3
* @property string $WedTime1
* @property string $WedTime2
* @property string $WedTime3
* @property string $ThuTime1
* @property string $ThuTime2
* @property string $ThuTime3
* @property string $FriTime1
* @property string $FriTime2
* @property string $FriTime3
* @property string $SatTime1
* @property string $SatTime2
* @property string $SatTime3
* @property string $created_at
* @property string $modified_at
*/
class Schedule extends \yii\db\ActiveRecord {
/**
* {@inheritdoc}
*/
public static function tableName() {
return 'schedule';
}
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['name'], 'required'],
[['description'], 'string'],
[['name'], 'string', 'max' => 200],
[['created_at', 'modified_at'], 'integer'],
[['SunTime1', 'SunTime2', 'SunTime3', 'MonTime1', 'MonTime2', 'MonTime3', 'TueTime1', 'TueTime2', 'TueTime3', 'WedTime1', 'WedTime2', 'WedTime3', 'ThuTime1', 'ThuTime2', 'ThuTime3', 'FriTime1', 'FriTime2', 'FriTime3', 'SatTime1', 'SatTime2', 'SatTime3'], 'string', 'max' => 100],
];
}
/**
* {@inheritdoc}
*/
public function attributeLabels() {
return [
'id' => 'ID',
'name' => 'Tên lịch trình',
'description' => 'Chú thích',
'SunTime1' => 'Sun Time1',
'SunTime2' => 'Sun Time2',
'SunTime3' => 'Sun Time3',
'MonTime1' => 'Mon Time1',
'MonTime2' => 'Mon Time2',
'MonTime3' => 'Mon Time3',
'TueTime1' => 'Tue Time1',
'TueTime2' => 'Tue Time2',
'TueTime3' => 'Tue Time3',
'WedTime1' => 'Wed Time1',
'WedTime2' => 'Wed Time2',
'WedTime3' => 'Wed Time3',
'ThuTime1' => 'Thu Time1',
'ThuTime2' => 'Thu Time2',
'ThuTime3' => 'Thu Time3',
'FriTime1' => 'Fri Time1',
'FriTime2' => 'Fri Time2',
'FriTime3' => 'Fri Time3',
'SatTime1' => 'Sat Time1',
'SatTime2' => 'Sat Time2',
'SatTime3' => 'Sat Time3',
'created_at' => 'Thời gian tạo',
'modified_at' => 'Thời gian sửa',
];
}
public static $dayOfWeek = [
"Mon" => "Thứ hai",
"Tue" => "Thứ ba",
"Wed" => "Thứ tư",
"Thu" => "Thứ năm",
"Fri" => "Thứ sáu",
"Sat" => "Thứ bảy",
"Sun" => "Chủ nhật"
];
public function create($data) {
$r = $this->load([
'name' => $data["Name"],
'description' => $data["Description"],
'SunTime1' => $data["SunTime1"],
'SunTime2' => $data["SunTime2"],
'SunTime3' => $data["SunTime3"],
'MonTime1' => $data["MonTime1"],
'MonTime2' => $data["MonTime2"],
'MonTime3' => $data["MonTime3"],
'TueTime1' => $data["TueTime1"],
'TueTime2' => $data["TueTime2"],
'TueTime3' => $data["TueTime3"],
'WedTime1' => $data["WedTime1"],
'WedTime2' => $data["WedTime2"],
'WedTime3' => $data["WedTime3"],
'ThuTime1' => $data["ThuTime1"],
'ThuTime2' => $data["ThuTime2"],
'ThuTime3' => $data["ThuTime3"],
'FriTime1' => $data["FriTime1"],
'FriTime2' => $data["FriTime2"],
'FriTime3' => $data["FriTime3"],
'SatTime1' => $data["SatTime1"],
'SatTime2' => $data["SatTime2"],
'SatTime3' => $data["SatTime3"],
"created_at" => time(),
"modified_at" => time()
], '');
if ($r) {
try {
$this->save();
return $this->id;
} catch (\Exception $ex) {
return false;
}
}
}
public static function combineTime($from, $to) {
return $from . "-" . $to;
}
public static function convertTime($from, $to) {
$fTemp = explode(":", $from);
$front = dechex(intval($fTemp[0]) * 100 + intval($fTemp[1]));
$tTemp = explode(":", $to);
$back = dechex(intval($tTemp[0]) * 100 + intval($tTemp[1]));
return hexdec("0" . $front . "0" . $back);
}
}

91
models/ScheduleSearch.php Normal file
View File

@ -0,0 +1,91 @@
<?php
namespace app\models;
use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use app\models\Schedule;
/**
* ScheduleSearch represents the model behind the search form of `app\models\Schedule`.
*/
class ScheduleSearch extends Schedule {
/**
* {@inheritdoc}
*/
public function rules() {
return [
[['id', 'SunTime1', 'SunTime2', 'SunTime3', 'MonTime1', 'MonTime2', 'MonTime3', 'TueTime1', 'TueTime2', 'TueTime3', 'WedTime1', 'WedTime2', 'WedTime3', 'ThuTime1', 'ThuTime2', 'ThuTime3', 'FriTime1', 'FriTime2', 'FriTime3', 'SatTime1', 'SatTime2', 'SatTime3'], 'integer'],
[['name', 'description'], 'safe'],
];
}
/**
* {@inheritdoc}
*/
public function scenarios() {
// bypass scenarios() implementation in the parent class
return Model::scenarios();
}
/**
* Creates data provider instance with search query applied
*
* @param array $params
*
* @return ActiveDataProvider
*/
public function search($params) {
$query = Schedule::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'SunTime1' => $this->SunTime1,
'SunTime2' => $this->SunTime2,
'SunTime3' => $this->SunTime3,
'MonTime1' => $this->MonTime1,
'MonTime2' => $this->MonTime2,
'MonTime3' => $this->MonTime3,
'TueTime1' => $this->TueTime1,
'TueTime2' => $this->TueTime2,
'TueTime3' => $this->TueTime3,
'WedTime1' => $this->WedTime1,
'WedTime2' => $this->WedTime2,
'WedTime3' => $this->WedTime3,
'ThuTime1' => $this->ThuTime1,
'ThuTime2' => $this->ThuTime2,
'ThuTime3' => $this->ThuTime3,
'FriTime1' => $this->FriTime1,
'FriTime2' => $this->FriTime2,
'FriTime3' => $this->FriTime3,
'SatTime1' => $this->SatTime1,
'SatTime2' => $this->SatTime2,
'SatTime3' => $this->SatTime3,
'created_at' => $this->created_at,
'modified_at' => $this->modified_at,
]);
$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'description', $this->description]);
return $dataProvider;
}
}

View File

@ -21,6 +21,7 @@ use Yii;
* @property int $created_at
* @property int $modified_at
* @property int $card_register_time
* @property int $schedule_id
*/
class Staff extends \yii\db\ActiveRecord {
@ -37,7 +38,7 @@ class Staff extends \yii\db\ActiveRecord {
public function rules() {
return [
[['code', 'name', 'gender'], 'required'],
[['code', 'card_number', 'department_id', 'birthday', 'date_in', 'created_at', 'modified_at', 'card_register_time'], 'integer'],
[['code', 'card_number', 'department_id', 'birthday', 'date_in', 'created_at', 'modified_at', 'card_register_time', 'schedule_id'], 'integer'],
[['address'], 'string'],
[['name', 'email'], 'string', 'max' => 100],
[['gender'], 'string', 'max' => 10],

View File

@ -30,8 +30,8 @@ use yii\widgets\ActiveForm;
Thiết bị
</a>
</li>
<li>
<a href="#">
<li class="<?php if (in_array($this->context->id, ['schedule'])) echo "active"; ?>">
<a href="<?php echo \yii\helpers\Url::to(['/schedule']); ?>">
Kiểm soát truy cập
</a>
</li>

View File

@ -27,6 +27,12 @@
['label' => 'Tìm kiếm thiết bị', 'url' => ['/device/search'], 'icon' => 'search']
];
}
if (in_array($this->context->id, ['schedule'])) {
$items = [
['label' => 'Lịch trình', 'url' => ['/schedule'], 'icon' => 'calendar'],
['label' => 'Cấp quyền truy cập', 'url' => ['/device'], 'icon' => 'cogs']
];
}
?>
<?=
dmstr\widgets\Menu::widget(

View File

@ -56,6 +56,9 @@
'name',
'serial',
'ip_address',
'subnet_mask',
'gateway',
'mac_address',
[
'attribute' => 'status',
'format' => 'raw',
@ -63,13 +66,7 @@
'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\DeviceGrid::status($statusArray)
],
[
'attribute' => 'type',
'format' => 'raw',
'filter' => $typeArray,
'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\DeviceGrid::type($typeArray)
],
'type',
[
'attribute' => 'area_id',
'format' => 'raw',
@ -77,14 +74,7 @@
'contentOptions' => ['class' => 'text-center'],
'value' => \app\helpers\DeviceGrid::area($areaArray)
],
[
'attribute' => 'created_at',
'value' => \app\helpers\CommonGrid::createdAt()
],
[
'attribute' => 'modified_at',
'value' => \app\helpers\CommonGrid::modifiedAt()
]
'version'
]
])}
{/Pjax}

125
views/schedule/form.tpl Normal file
View File

@ -0,0 +1,125 @@
<style>
.select-picker{
width: 80px;
}
</style>
<input type="hidden" name="CurrentPos" value="">
<div class="row">
<div class="col-md-5">
<div class="form-group" id="name">
<div class="input-group">
<div class="input-group-addon">Tên lịch trình <i class="text-red">*</i></div>
<input type="text" class="form-control" value="{$model->name|default:""}" name="Name">
</div>
<span class="help-block hidden"></span>
</div>
</div>
<div class="col-md-7">
<div class="form-group">
<div class="input-group">
<div class="input-group-addon">Chú thích</div>
<input type="text" class="form-control" value="{$model->description|default:""}" name="Description">
</div>
</div>
</div>
</div>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>Ngày</th>
<th style="width: 25%;" class="text-center">Khung giờ 1</th>
<th style="width: 25%;" class="text-center">Khung giờ 2</th>
<th style="width: 25%;" class="text-center">Khung giờ 3</th>
<th></th>
</tr>
</thead>
<tbody>
{foreach from=$dayOfWeek item=day key=k}
<tr>
<td>{$day}</td>
<td class="text-center">
<div class="time-picker-data" id="data-{$k}1">
{if $model[$k|cat:"Time1"]}
{$time=explode("-",$model[$k|cat:"Time1"])}
{if $time[0]!=="00:00" || $time[1]!=="00:00"}
<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}1">{$time[0]} - {$time[1]}</span>
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}1"></i>
{/if}
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}1"></i>
{/if}
</div>
<div class="time-picker-form hidden" id="form-{$k}1">
<input type='text' name='From{$k}1' class="select-picker" value="{$time[0]|default:"00:00"}" readonly="">
-
<input type='text' name='To{$k}1' class="select-picker" value="{$time[1]|default:"00:00"}" readonly="">
</div>
</td>
<td class="text-center">
<div class="time-picker-data" id="data-{$k}2">
{if $model[$k|cat:"Time2"]}
{$time=explode("-",$model[$k|cat:"Time2"])}
{if $time[0]!=="00:00" || $time[1]!=="00:00"}
<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}2">{$time[0]} - {$time[1]}</span>
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}2"></i>
{/if}
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}2"></i>
{/if}
</div>
<div class="time-picker-form hidden" id="form-{$k}2">
<input type='text' name='From{$k}2' class="select-picker" value="{$time[0]|default:"00:00"}" readonly="">
-
<input type='text' name='To{$k}2' class="select-picker" value="{$time[1]|default:"00:00"}" readonly="">
</div>
</td>
<td class="text-center">
<div class="time-picker-data" id="data-{$k}3">
{if $model[$k|cat:"Time3"]}
{$time=explode("-",$model[$k|cat:"Time3"])}
{if $time[0]!=="00:00" || $time[1]!=="00:00"}
<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}3">{$time[0]} - {$time[1]}</span>
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}3"></i>
{/if}
{else}
<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="{$k}3"></i>
{/if}
</div>
<div class="time-picker-form hidden" id="form-{$k}3">
<input type='text' name='From{$k}3' class="select-picker" value="{$time[0]|default:"00:00"}" readonly="">
-
<input type='text' name='To{$k}3' class="select-picker" value="{$time[0]|default:"00:00"}" readonly="">
</div>
</td>
<td class="text-center">
<div class="btn-group">
<button class="btn btn-info btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
<i class="fa fa-copy"></i>
</button>
<ul class="dropdown-menu" role="menu">
{foreach from=$dayOfWeek item=d_copy key=k_copy}
{if $k_copy!==$k}
<li>
<a href="#" onclick="_copy(this);
return false;" data-from="{$k}" data-target="{$k_copy}">{$d_copy}</a>
</li>
{/if}
{/foreach}
</ul>
</div>
</td>
</tr>
{/foreach}
</tbody>
</table>
<div class="text-right">
<button class="btn btn-primary" onclick="save(this);" data-href="{$url}">
<i class="fa fa-floppy-o"></i> Lưu
</button>
<button class="btn btn-default" data-dismiss="modal">
<span class="fa fa-remove"></span> Hủy
</button>
</div>

57
views/schedule/index.tpl Normal file
View File

@ -0,0 +1,57 @@
{extends file=$smarty.current_dir|cat:'/../extends.tpl'}
{use class="yii\helpers\Url"}
{use class="yii\grid\GridView"}
{use class="yii\widgets\Pjax" type="block"}
{use class="app\assets\ScheduleAsset"}
{ScheduleAsset::register($this)|void}
{block name='content'}
<div class="schedule-index">
<div class="" style="font-size: 15px;">
<label class="action-button" onclick="_create(this);" data-href="{Url::to(['create'])}">
<i class="fa fa-plus-square fa-1-5x"></i> Thêm
</label>
<label class="action-button" onclick="_form(this);" data-href="{Url::to(['update'])}">
<i class="fa fa-edit fa-1-5x"></i> Tùy chỉnh
</label>
<label class="action-button" onclick="_delete(this);" data-href="{Url::to(['delete'])}">
<i class="fa fa-trash fa-1-5x"></i> Xóa
</label>
</div>
{Pjax id="schedule-list"}
{GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'layout'=> \app\helpers\CommonGrid::getLayout(),
'tableOptions' => [
'class' => 'table table-striped table-bordered table-hover',
'style' => 'background:#fff;min-width:700px;'
],
'rowOptions' => \app\helpers\CommonGrid::rows("schedule", true),
'columns' => [
[
'class' => 'yii\grid\SerialColumn',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%']
],
[
'header' => "<input type='checkbox' value='0' class='checkbox-schedule' id='checkall-schedule'>",
'format' => 'raw',
'contentOptions' => ['class' => 'text-center'],
'headerOptions' => ['class' => 'text-center', 'style' => 'width:3%'],
'value' => \app\helpers\CommonGrid::checkbox("schedule")
],
'name',
'description',
[
'attribute' => 'created_at',
'value' => \app\helpers\CommonGrid::createdAt()
],
[
'attribute' => 'modified_at',
'value' => \app\helpers\CommonGrid::modifiedAt()
]
]
])}
{/Pjax}
</div>
{/block}

View File

@ -245,6 +245,9 @@ common.form = function (e, obj, bigSize) {
if (obj === 'device') {
$('#Area').select2();
}
if (obj === 'schedule') {
common.dateTimePickerByClass("select-picker", "HH:mm");
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);

237
web/js/schedule.js Normal file
View File

@ -0,0 +1,237 @@
$(function () {
common.checkboxInit("schedule");
});
function _create(e) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, true, data.title);
common.dateTimePickerByClass("select-picker", "HH:mm");
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function openFormTimePicker(e) {
if (saveCurrentPos()) {
var id = $(e).attr("data-id");
$("#data-" + id).addClass("hidden");
$("#form-" + id).removeClass("hidden");
$("input[name='CurrentPos']").val(id);
}
}
function _copy(e) {
if (saveCurrentPos()) {
var fromDay = $(e).attr("data-from");
var targetDay = $(e).attr("data-target");
var fDay1 = $("input[name='From" + fromDay + "1']").val();
var tDay1 = $("input[name='To" + fromDay + "1']").val();
if (fDay1 !== "00:00" || tDay1 !== "00:00") {
var html = `<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + targetDay + `1">` + fDay1 + ` - ` + tDay1 + `</span>`;
$("#data-" + targetDay + "1").html(html);
$("input[name='From" + targetDay + "1']").val(fDay1);
$("input[name='To" + targetDay + "1']").val(tDay1);
}
var fDay2 = $("input[name='From" + fromDay + "2']").val();
var tDay2 = $("input[name='To" + fromDay + "2']").val();
if (fDay2 !== "00:00" || tDay2 !== "00:00") {
var html = `<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + targetDay + `2">` + fDay2 + ` - ` + tDay2 + `</span>`;
$("#data-" + targetDay + "2").html(html);
$("input[name='From" + targetDay + "2']").val(fDay2);
$("input[name='To" + targetDay + "2']").val(tDay2);
}
var fDay3 = $("input[name='From" + fromDay + "3']").val();
var tDay3 = $("input[name='To" + fromDay + "3']").val();
if (fDay3 !== "00:00" || tDay3 !== "00:00") {
var html = `<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + targetDay + `3">` + fDay3 + ` - ` + tDay3 + `</span>`;
$("#data-" + targetDay + "3").html(html);
$("input[name='From" + targetDay + "3']").val(fDay3);
$("input[name='To" + targetDay + "3']").val(tDay3);
}
}
}
function saveCurrentPos() {
var currentID = $("input[name='CurrentPos']").val();
if (currentID !== "") {
var f = $("input[name='From" + currentID + "']").val();
var t = $("input[name='To" + currentID + "']").val();
if (convertTime(f) > convertTime(t)) {
alert("Mốc thời gian lựa chọn chưa đúng!");
return false;
}
if (f !== "00:00" || t !== "00:00") {
var html = `<span style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + currentID + `">` + f + ` - ` + t + `</span>`;
$("#data-" + currentID).html(html);
} else if (f === "00:00" && t === "00:00") {
var html = `<i class="fa fa-plus fa-1-5x text-green" style="cursor: pointer;" onclick="openFormTimePicker(this);" data-id="` + currentID + `"></i>`;
$("#data-" + currentID).html(html);
}
}
$(".time-picker-data").removeClass("hidden");
$(".time-picker-form").addClass("hidden");
return true;
}
function convertTime(time) {
var split = time.split(":");
return parseInt(split[0]) * 60 + parseInt(split[1]);
}
function validate() {
var error = 0;
var Name = $("input[name='Name']").val();
if (Name === "") {
common.error("name", "Tên lịch trình không được để trống");
error++;
} else {
common.success("name");
}
return error == 0 ? true : false;
}
function save(e) {
if (validate() && saveCurrentPos()) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
Name: $("input[name='Name']").val(),
Description: $("input[name='Description']").val(),
FromMon1: $("input[name='FromMon1']").val(),
ToMon1: $("input[name='ToMon1']").val(),
FromMon2: $("input[name='FromMon2']").val(),
ToMon2: $("input[name='ToMon2']").val(),
FromMon3: $("input[name='FromMon3']").val(),
ToMon3: $("input[name='ToMon3']").val(),
FromTue1: $("input[name='FromTue1']").val(),
ToTue1: $("input[name='ToTue1']").val(),
FromTue2: $("input[name='FromTue2']").val(),
ToTue2: $("input[name='ToTue2']").val(),
FromTue3: $("input[name='FromTue3']").val(),
ToTue3: $("input[name='ToTue3']").val(),
FromWed1: $("input[name='FromWed1']").val(),
ToWed1: $("input[name='ToWed1']").val(),
FromWed2: $("input[name='FromWed2']").val(),
ToWed2: $("input[name='ToWed2']").val(),
FromWed3: $("input[name='FromWed3']").val(),
ToWed3: $("input[name='ToWed3']").val(),
FromThu1: $("input[name='FromThu1']").val(),
ToThu1: $("input[name='ToThu1']").val(),
FromThu2: $("input[name='FromThu2']").val(),
ToThu2: $("input[name='ToThu2']").val(),
FromThu3: $("input[name='FromThu3']").val(),
ToThu3: $("input[name='ToThu3']").val(),
FromFri1: $("input[name='FromFri1']").val(),
ToFri1: $("input[name='ToFri1']").val(),
FromFri2: $("input[name='FromFri2']").val(),
ToFri2: $("input[name='ToFri2']").val(),
FromFri3: $("input[name='FromFri3']").val(),
ToFri3: $("input[name='ToFri3']").val(),
FromSat1: $("input[name='FromSat1']").val(),
ToSat1: $("input[name='ToSat1']").val(),
FromSat2: $("input[name='FromSat2']").val(),
ToSat2: $("input[name='ToSat2']").val(),
FromSat3: $("input[name='FromSat3']").val(),
ToSat3: $("input[name='ToSat3']").val(),
FromSun1: $("input[name='FromSun1']").val(),
ToSun1: $("input[name='ToSun1']").val(),
FromSun2: $("input[name='FromSun2']").val(),
ToSun2: $("input[name='ToSun2']").val(),
FromSun3: $("input[name='FromSun3']").val(),
ToSun3: $("input[name='ToSun3']").val()
},
success: function (data) {
common.modalBlock(false);
if (data.status) {
notification.success("Đã lưu thông tin", 1000);
$.pjax.reload({container: '#schedule-list'});
$("#schedule-list").on('pjax:success', function () {
common.checkboxInit("schedule");
});
$("#myModal").modal("hide");
} else {
notification.danger("Có lỗi xảy ra, không lưu được dữ liệu!", 1000);
}
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
}
function _form(e) {
var lists = [];
$.each($("input[name='checkbox-schedule']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng để thay đổi!");
return;
}
if (lists.length > 1) {
alert("Tác vụ này không thể lựa chọn nhiều hơn một đối tượng!");
return;
}
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href') + "?id=" + lists[0],
type: 'POST',
success: function (data) {
common.modalBlock(false);
common.modalOpen(data.form, true, data.title);
common.dateTimePickerByClass("select-picker", "HH:mm");
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
function _delete(e) {
var lists = [];
$.each($("input[name='checkbox-schedule']:checked"), function () {
lists.push($(this).val());
});
if (lists.length == 0) {
alert("Vui lòng lựa chọn đối tượng để xóa!");
return;
}
if (confirm("Bạn có chắc chắn muốn xóa các đối tượng đã lựa chọn không?")) {
common.modalBlock(true);
$.ajax({
url: $(e).attr('data-href'),
type: 'POST',
data: {
lists: lists
},
success: function (data) {
common.modalBlock(false);
notification.danger("Đã xóa dữ liệu", 1000);
$.pjax.reload({container: '#schedule-list'});
$("#schedule-list").on('pjax:success', function () {
common.checkboxInit("schedule");
});
},
error: function (jqXHR, textStatus, errorThrown) {
common.modalBlock(false);
common.ajaxError();
}
});
}
}

41
web/slider/bootstrap-slider.min.css vendored Normal file

File diff suppressed because one or more lines are too long

5
web/slider/bootstrap-slider.min.js vendored Normal file

File diff suppressed because one or more lines are too long