作者 Karson

新增Table.api.formatter.toggle切换

@@ -18,6 +18,7 @@ class Rule extends Backend @@ -18,6 +18,7 @@ class Rule extends Backend
18 */ 18 */
19 protected $model = null; 19 protected $model = null;
20 protected $rulelist = []; 20 protected $rulelist = [];
  21 + protected $multiFields = 'ismenu,status';
21 22
22 public function _initialize() 23 public function _initialize()
23 { 24 {
@@ -111,6 +111,7 @@ return [ @@ -111,6 +111,7 @@ return [
111 'Go back' => '返回首页', 111 'Go back' => '返回首页',
112 'Jump now' => '立即跳转', 112 'Jump now' => '立即跳转',
113 'Click to search %s' => '点击搜索 %s', 113 'Click to search %s' => '点击搜索 %s',
  114 + 'Click to toggle' => '点击切换',
114 'Operation completed' => '操作成功!', 115 'Operation completed' => '操作成功!',
115 'Operation failed' => '操作失败!', 116 'Operation failed' => '操作失败!',
116 'Unknown data format' => '未知的数据格式!', 117 'Unknown data format' => '未知的数据格式!',
@@ -646,6 +646,9 @@ form.form-horizontal .control-label { @@ -646,6 +646,9 @@ form.form-horizontal .control-label {
646 .bootstrap-table .fixed-table-toolbar .dropdown-menu { 646 .bootstrap-table .fixed-table-toolbar .dropdown-menu {
647 overflow: auto; 647 overflow: auto;
648 } 648 }
  649 +.bootstrap-table .fa-toggle-on.fa-2x {
  650 + font-size: 1.86em;
  651 +}
649 .toolbar { 652 .toolbar {
650 margin-top: 10px; 653 margin-top: 10px;
651 margin-bottom: 10px; 654 margin-bottom: 10px;
@@ -34,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function @@ -34,7 +34,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
34 field: 'ismenu', 34 field: 'ismenu',
35 title: __('Ismenu'), 35 title: __('Ismenu'),
36 align: 'center', 36 align: 'center',
37 - formatter: Controller.api.formatter.menu 37 + formatter: Table.api.formatter.toggle
38 }, 38 },
39 { 39 {
40 field: 'id', 40 field: 'id',
@@ -117,10 +117,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function @@ -117,10 +117,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function
117 name: function (value, row, index) { 117 name: function (value, row, index) {
118 return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value; 118 return !row.ismenu || row.status == 'hidden' ? "<span class='text-muted'>" + value + "</span>" : value;
119 }, 119 },
120 - menu: function (value, row, index) {  
121 - return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Toggle menu visible') + "' class='btn btn-" + (value ? "info" : "default") + " btn-xs btn-change' data-id='"  
122 - + row.id + "' data-params='ismenu=" + (value ? 0 : 1) + "'>" + (value ? __('Yes') : __('No')) + "</a>";  
123 - },  
124 icon: function (value, row, index) { 120 icon: function (value, row, index) {
125 return '<span class="' + (!row.ismenu || row.status == 'hidden' ? 'text-muted' : '') + '"><i class="' + value + '"></i></span>'; 121 return '<span class="' + (!row.ismenu || row.status == 'hidden' ? 'text-muted' : '') + '"><i class="' + value + '"></i></span>';
126 }, 122 },
@@ -30,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -30,7 +30,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
30 {field: 'title', title: __('Title'), align: 'left'}, 30 {field: 'title', title: __('Title'), align: 'left'},
31 {field: 'name', title: __('Name'), align: 'left'}, 31 {field: 'name', title: __('Name'), align: 'left'},
32 {field: 'remark', title: __('Remark')}, 32 {field: 'remark', title: __('Remark')},
33 - {field: 'ismenu', title: __('Ismenu'), formatter: Controller.api.formatter.toggle}, 33 + {field: 'ismenu', title: __('Ismenu'), formatter: Table.api.formatter.toggle},
34 {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false}, 34 {field: 'createtime', title: __('Createtime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
35 {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false}, 35 {field: 'updatetime', title: __('Updatetime'), formatter: Table.api.formatter.datetime, operate: 'RANGE', addclass: 'datetimerange', sortable: true, visible: false},
36 {field: 'weigh', title: __('Weigh')}, 36 {field: 'weigh', title: __('Weigh')},
@@ -60,12 +60,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin @@ -60,12 +60,6 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
60 }); 60 });
61 $("input[name='row[ismenu]']:checked").trigger("click"); 61 $("input[name='row[ismenu]']:checked").trigger("click");
62 Form.api.bindevent($("form[role=form]")); 62 Form.api.bindevent($("form[role=form]"));
63 - },  
64 - formatter: {  
65 - toggle: function (value, row, index) {  
66 - //添加上btn-change可以自定义请求的URL进行数据处理  
67 - return '<i class="fa ' + (value == 0 ? 'fa-toggle-off' : 'fa-toggle-on') + ' fa-2x"></i>';  
68 - },  
69 } 63 }
70 } 64 }
71 }; 65 };
@@ -9742,6 +9742,13 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr @@ -9742,6 +9742,13 @@ define('table',['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstr
9742 } 9742 }
9743 return html; 9743 return html;
9744 }, 9744 },
  9745 + toggle: function (value, row, index) {
  9746 + var color = typeof this.color !== 'undefined' ? this.color : 'success';
  9747 + var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
  9748 + var no = typeof this.no !== 'undefined' ? this.no : 0;
  9749 + return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change' data-id='"
  9750 + + row.id + "' data-params='" + this.field + "=" + (value ? no : yes) + "'><i class='fa fa-toggle-on " + (value == yes ? 'text-' + color : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
  9751 + },
9745 url: function (value, row, index) { 9752 url: function (value, row, index) {
9746 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>'; 9753 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
9747 }, 9754 },
@@ -402,6 +402,13 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table @@ -402,6 +402,13 @@ define(['jquery', 'bootstrap', 'moment', 'moment/locale/zh-cn', 'bootstrap-table
402 } 402 }
403 return html; 403 return html;
404 }, 404 },
  405 + toggle: function (value, row, index) {
  406 + var color = typeof this.color !== 'undefined' ? this.color : 'success';
  407 + var yes = typeof this.yes !== 'undefined' ? this.yes : 1;
  408 + var no = typeof this.no !== 'undefined' ? this.no : 0;
  409 + return "<a href='javascript:;' data-toggle='tooltip' title='" + __('Click to toggle') + "' class='btn-change' data-id='"
  410 + + row.id + "' data-params='" + this.field + "=" + (value ? no : yes) + "'><i class='fa fa-toggle-on " + (value == yes ? 'text-' + color : 'fa-flip-horizontal text-gray') + " fa-2x'></i></a>";
  411 + },
405 url: function (value, row, index) { 412 url: function (value, row, index) {
406 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>'; 413 return '<div class="input-group input-group-sm" style="width:250px;margin:0 auto;"><input type="text" class="form-control input-sm" value="' + value + '"><span class="input-group-btn input-group-sm"><a href="' + value + '" target="_blank" class="btn btn-default btn-sm"><i class="fa fa-link"></i></a></span></div>';
407 }, 414 },
@@ -730,6 +730,9 @@ form.form-horizontal .control-label { @@ -730,6 +730,9 @@ form.form-horizontal .control-label {
730 .bootstrap-table .fixed-table-toolbar .dropdown-menu { 730 .bootstrap-table .fixed-table-toolbar .dropdown-menu {
731 overflow: auto; 731 overflow: auto;
732 } 732 }
  733 +.bootstrap-table .fa-toggle-on.fa-2x {
  734 + font-size:1.86em;
  735 +}
733 736
734 .toolbar { 737 .toolbar {
735 margin-top: 10px; 738 margin-top: 10px;