From 02d49834cb0d8936dc49352b3968c3baf6da3232 Mon Sep 17 00:00:00 2001
From: root <root@iZ23bpwwq5sZ.(none)>
Date: Thu, 03 Aug 2017 14:59:11 +0800
Subject: [PATCH] update
---
application/library/Util.php | 23 ++++-
application/modules/Module/controllers/Manager.php | 68 ++++++++++------
application/core/System/Controller/Base.php | 4
application/modules/Admin/views/layout/adminLayout.phtml | 4
static/module/manager/js/edit.js | 112 ++++++++++++++++++++++++++++
application/library/RedisCache.php | 5
conf/application.ini | 1
application/modules/Module/views/manager/edit.phtml | 11 +-
8 files changed, 186 insertions(+), 42 deletions(-)
diff --git a/application/core/System/Controller/Base.php b/application/core/System/Controller/Base.php
index f3de77d..1c58419 100644
--- a/application/core/System/Controller/Base.php
+++ b/application/core/System/Controller/Base.php
@@ -52,9 +52,9 @@
$this->route = $this->getRoute();
//���������redis
$this->redis = System_Service_Locator::getInstance()->get('redis');
- if(!$this->redis->exists('modules') ){
+ //if(!$this->redis->exists('modules') ){
$this->redis->set('modules', $this->getModules());
- }
+ //}
//������������������
if(!empty($this->layout)){
//������������������������
diff --git a/application/library/RedisCache.php b/application/library/RedisCache.php
index dcbb708..d0668b3 100644
--- a/application/library/RedisCache.php
+++ b/application/library/RedisCache.php
@@ -36,7 +36,7 @@
$this->_TIMEOUT = 0;
$this->_DBNAME = null;
$this->_CTYPE = 1;
-
+ $this->_AUTH = $config['auth'];
if (!isset($this->_REDIS)) {
$this->_REDIS = new Redis();
$this->connect($this->_HOST, $this->_PORT, $this->_TIMEOUT, $this->_DBNAME, $this->_CTYPE);
@@ -58,6 +58,7 @@
default:
break;
}
+ $this->_REDIS->auth($this->_AUTH);
}
/**
@@ -927,4 +928,4 @@
{
return $this->_TRANSCATION->discard();
}
-}
\ No newline at end of file
+}
diff --git a/application/library/Util.php b/application/library/Util.php
index 28bf21d..8f678f3 100644
--- a/application/library/Util.php
+++ b/application/library/Util.php
@@ -2,25 +2,25 @@
class Util{
- public function selectItem($id){
+ public function selectItem($id, $selected = 0){
$module_service = new Service_Module();
$modules = $module_service->getModuleList();
- return "<select class='form-control' id='".$id."' name='".$id."'>".self::getModules($modules)."</select>";
+ return "<select class='form-control' id='".$id."' name='".$id."'>".self::getModules($modules, 0, 0, $selected)."</select>";
}
- public function getModules($modules, $parent = 0, $deep = 0){
+ public function getModules($modules, $parent = 0, $deep = 0, $selected){
static $html = "<option value='0'>������������</option>";
foreach ($modules as $key => $module) {
if($module['parent'] == $parent){
if($deep == 0 || $parent == 0){
- $html .="<option value='".$module['_id']."'>".$module['name']."</option>";
+ $html .="<option value='".$module['_id']."' ".($selected == $module['_id']? "seleced":'').">".$module['name']."</option>";
}
else{
- $html .="<option value='".$module['_id']."'>".str_repeat('  ', $deep)."���".$module['name']."</option>";
+ $html .="<option value='".$module['_id']."' ".($selected == $module['_id']? "seleced":'').">".str_repeat('  ', $deep)."���".$module['name']."</option>";
}
$deep ++;
unset($modules[$key]);
- self::getModules($modules, $module['_id'], $deep);
+ self::getModules($modules, $module['_id'], $deep, $selected);
}
}
@@ -64,5 +64,16 @@
$redis->set('role_auth', $role_auth);
}
+ /**
+ * ������������
+ * @return [type] [description]
+ */
+ public function updateModules(){
+ $this->module_service = new Service_Module();
+ $modules= $this->module_service->getModuleList(array(), array(), array('level' => 1));
+ //���������redis
+ $redis = System_Service_Locator::getInstance()->get('redis');
+ $redis->set('modules', $modules);
+ }
}
\ No newline at end of file
diff --git a/application/modules/Admin/views/layout/adminLayout.phtml b/application/modules/Admin/views/layout/adminLayout.phtml
index f37fb10..4231726 100644
--- a/application/modules/Admin/views/layout/adminLayout.phtml
+++ b/application/modules/Admin/views/layout/adminLayout.phtml
@@ -336,7 +336,7 @@
<?php $s_html = '';?>
<?php if(isset($second_modules[$pid])):?>
<?php foreach ($second_modules[$pid] as $s_module):?>
- <?php if(isset($is_active_class) && in_array($s_module['_id'], $current_role_auth)):?>
+
<?php if($route['module'] == $s_module['module'] && $route['controller'] == $s_module['controller'] && $route['action'] == $s_module['action']):?>
<?php $is_active_class = 'active';?>
<?php $s_html .= "
@@ -345,7 +345,7 @@
<?php $s_html .= "
<li ><a href='/{$s_module['module']}/{$s_module['controller']}/{$s_module['action']}'><i class='fa fa-circle-o'></i> {$s_module['name']}</a></li>";
?>
- <?php endif;?>
+
<?php endif;?>
<?php endforeach;?>
<li class="<?php echo $is_active_class; ?> treeview">
diff --git a/application/modules/Module/controllers/Manager.php b/application/modules/Module/controllers/Manager.php
index e8d70fa..b948549 100644
--- a/application/modules/Module/controllers/Manager.php
+++ b/application/modules/Module/controllers/Manager.php
@@ -30,19 +30,27 @@
$data['action'] = $this->getRequest()->getPost('action');
$data['parent'] = $this->getRequest()->getPost('parent');
$data['name'] = $this->getRequest()->getPost('name');
- $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
- if($parent_module){
- if($parent['level'] <= 2 ){
- $data['level'] = $parent['level'] + 1;
+ if($data['parent'] != 0){
+ $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
+ if($parent_module){
+ $data['is_module'] = false;
+ if($parent['level'] <= 2 ){
+ $data['level'] = $parent['level'] + 1;
+ }
+ else{
+ exit($this->showError('���������������������������', 400, true));
+ }
}
else{
- exit($this->showError('���������������������������', 400, true));
+ exit($this->showError('���������������������������������������', 400, true));
}
}
else{
- exit($this->showError('���������������������������������������', 400, true));
+ $data['level'] = 1;
+ $data['is_module'] = true;
}
if($this->module_service->add($data)){
+ Util::updateModules();
exit($this->showSuccess('������������������', true));
}
else{
@@ -54,29 +62,39 @@
public function EditAction($id){
$module = $this->module_service->getModuleInfo(array('_id' => $id));
if($module){
- $data['module'] = $this->getRequest()->getPost('module');
- $data['controller'] = $this->getRequest()->getPost('controller');
- $data['action'] = $this->getRequest()->getPost('action');
- $data['parent'] = $this->getRequest()->getPost('parent');
- $data['name'] = $this->getRequest()->getPost('name');
- $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
- if($parent_module){
- if($parent['level'] <= 2 ){
- $data['level'] = $parent['level'] + 1;
+ if($this->getRequest()->isXmlHttpRequest()){
+ $data['module'] = $this->getRequest()->getPost('module');
+ $data['controller'] = $this->getRequest()->getPost('controller');
+ $data['action'] = $this->getRequest()->getPost('action');
+ $data['parent'] = $this->getRequest()->getPost('parent');
+ $data['name'] = $this->getRequest()->getPost('name');
+ if($data['parent']){
+ $parent_module = $this->module_service->getModuleInfo(array('_id' => $data['parent']));
+ if($parent_module){
+ if($parent['level'] <= 2 ){
+ $data['level'] = $parent['level'] + 1;
+ }
+ else{
+ exit($this->showError('���������������������������', 400, true));
+ }
+ }
+ else{
+ exit($this->showError('���������������������������������������', 400, true));
+ }
}
else{
- exit($this->showError('���������������������������', 400, true));
+ $data['level'] = 1;
+ $data['is_module'] = true;
+ }
+ if($this->module_service->update($data, array('_id' => $module['_id']))){
+ Util::updateModules();
+ exit($this->showSuccess('������������������', true));
+ }
+ else{
+ exit($this->showError($this->module_service->error, 400, true));
}
}
- else{
- exit($this->showError('���������������������������������������', 400, true));
- }
- if($this->module_service->update($data)){
- exit($this->showSuccess('������������������', true));
- }
- else{
- exit($this->showError($this->module_service->error, 400, true));
- }
+ $this->getView()->assign('module', $module);
}
else{
$this->redirect('/error/show/type/no_data');
diff --git a/application/modules/Module/views/manager/edit.phtml b/application/modules/Module/views/manager/edit.phtml
index a765a7b..b502806 100644
--- a/application/modules/Module/views/manager/edit.phtml
+++ b/application/modules/Module/views/manager/edit.phtml
@@ -24,19 +24,19 @@
<div class="box-body">
<div class="form-group">
<label >���������</label>
- <input type="text" class="form-control" id="module" name="module" placeholder="���������">
+ <input type="text" class="form-control" value="<?php echo $module['module']?>" id="module" name="module" placeholder="���������">
</div>
<div class="form-group">
<label >������������</label>
- <input type="text" class="form-control" id="controller" name="controller" placeholder="������������">
+ <input type="text" class="form-control" value="<?php echo $module['controller']?>" id="controller" name="controller" placeholder="������������">
</div>
<div class="form-group">
<label >���������</label>
- <input type="text" class="form-control" id="action" name="action" placeholder="���������">
+ <input type="text" class="form-control" value="<?php echo $module['action']?>" id="action" name="action" placeholder="���������">
</div>
<div class="form-group">
<label >������������</label>
- <input type="text" class="form-control" id="name" name="name" placeholder="������������">
+ <input type="text" class="form-control" value="<?php echo $module['name']?>" id="name" name="name" placeholder="������������">
</div>
<div class="form-group">
<label >������������</label>
@@ -54,6 +54,7 @@
</section>
<script src="/themes/AdminLTE/bootstrap/js/bootstrapValidator.min.js"></script>
<script type="text/javascript">
+ var ID = '<?php echo $module['_id']?>';
var SITE_URL = '<?php echo Yaf_Registry::get('var')['site_url']; ?>';
</script>
-<script src="/static/module/manager/js/add.js"></script>
+<script src="/static/<?php echo $route['module']?>/<?php echo $route['controller']?>/js/<?php echo $route['action']?>.js"></script>
\ No newline at end of file
diff --git a/conf/application.ini b/conf/application.ini
index fd1a52e..499f9e0 100644
--- a/conf/application.ini
+++ b/conf/application.ini
@@ -26,3 +26,4 @@
;redis
redis.host = 127.0.0.1
redis.port = 6379
+redis.auth = yfs_moral_password2017
diff --git a/static/module/manager/js/edit.js b/static/module/manager/js/edit.js
new file mode 100644
index 0000000..bb7ab50
--- /dev/null
+++ b/static/module/manager/js/edit.js
@@ -0,0 +1,112 @@
+var validator_config = {
+ message: '���������������������������',
+ feedbackIcons: {
+ valid: 'glyphicon glyphicon-ok',
+ invalid: 'glyphicon glyphicon-remove',
+ validating: 'glyphicon glyphicon-refresh'
+ },
+ fields:{
+ module:{
+ validators:{
+ callback: {
+ message: '���������������������',
+ callback: function(value, validator){
+ var parent = $('#parent').val();
+ if(parent == 0){
+ return true;
+ }
+ else{
+ if(value != ""){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+ }
+ },
+ }
+ },
+ controller: {
+ validators: {
+ callback: {
+ message: '������������������������',
+ callback: function(value, validator){
+ var parent = $('#parent').val();
+ if(parent == 0){
+ return true;
+ }
+ else{
+ if(value != ""){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+ }
+ }
+ }
+ },
+ action: {
+ validators: {
+ callback: {
+ message: '������������������������',
+ callback:function(value, validator){
+ var parent = $('#parent').val();
+ if(parent == 0){
+ return true;
+ }
+ else{
+ if(value != ""){
+ return true;
+ }
+ else{
+ return false;
+ }
+ }
+ }
+ }
+ }
+ },
+ name: {
+ validators: {
+ notEmpty:{
+ message: '������������������������',
+ }
+ }
+ }
+
+ }
+
+
+}
+
+$('#validateform').bootstrapValidator(validator_config).on('success.form.bv', function(e) {
+ e.preventDefault();
+
+ $("#dosubmit").attr("disabled","disabled");
+ $.scojs_message('���������...', $.scojs_message.TYPE_WAIT);
+ $.ajax({
+ type: "POST",
+ url: SITE_URL+"/module/manager/edit/id/"+ID,
+ data: $("#validateform").serialize(),
+ success:function(response){
+ var dataObj=jQuery.parseJSON(response);
+ if(dataObj.code == 200)
+ {
+ $.scojs_message('������������,3������������������������...', $.scojs_message.TYPE_OK);
+ setTimeout(function(){window.location.href = SITE_URL+'/module/manager/index';}, 1800);
+ }else
+ {
+ $.scojs_message(dataObj.content, $.scojs_message.TYPE_ERROR);
+ $("#dosubmit").removeAttr("disabled");
+ }
+ },
+ error: function (request, status, error) {
+ $.scojs_message(request.responseText, $.scojs_message.TYPE_ERROR);
+ $("#dosubmit").removeAttr("disabled");
+ }
+ });
+
+ }).on('error.form.bv',function(e){ $.scojs_message('���������������������������������������������', $.scojs_message.TYPE_ERROR);$("#dosubmit").removeAttr("disabled");});
--
Gitblit v1.8.0