Blame view

public/assets/js/backend/fastflow/flow/message.js 7.89 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
  
  define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  
      var Controller = {
          index: function () {
              
              Table.api.init({
                  extend: {
                      index_url: 'fastflow/flow/message/index' + location.search,
                      add_url: 'fastflow/flow/message/add',
                      edit_url: 'fastflow/flow/message/edit',
                      del_url: 'fastflow/flow/message/del',
                      multi_url: 'fastflow/flow/message/multi',
                      import_url: 'fastflow/flow/message/import',
                      table: 'fastflow_message',
                  }
              });
  
              var table = $("#table");
  
              
              table.bootstrapTable({
                  url: $.fn.bootstrapTable.defaults.extend.index_url,
                  pk: 'id',
                  sortName: 'id',
                  sortOrder: 'asc',
                  columns: [
                      [
                          {checkbox: true},
                          {field: 'id', title: __('Id')},
                          {field: 'name', title: __('Name'), operate: 'LIKE'},
                          {field: 'key', title: __('Key'), operate: 'LIKE'},
                          {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1')}, formatter: Controller.api.formatter.status, events: Controller.api.events.status, custom: {0: 'success', 1: 'danger'}},
                          {field: '', title: __('Test'), formatter: Controller.api.formatter.test},
                          {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                      ]
                  ]
              });
  
              
              Table.api.bindevent(table);
              table.on('post-body.bs.table', function (e, data) {
                  $('.btn-editone').attr('data-area','["95%","90%"]');
              });
  
          },
          add: function () {
              Controller.api.createEditor();
              Controller.api.bindevent();
          },
          edit: function () {
              Controller.api.createEditor();
              Controller.api.bindevent();
          },
          test:function(){
              $('#fastflow-receiver').data("params", function (obj) {
                  return {"scope": $('#fastflow-receiver_scope').val()};
              });
              $('#fastflow-receiver_scope').change(function () {
                  $('#fastflow-receiver').selectPageClear();
              });
              Form.api.bindevent($("form[role=form]"));
          },
          api: {
              bindevent: function () {
                  Form.api.bindevent($("form[role=form]"));
              },
              formatter: {
                  status: function (value, row, index) {
                      return '<a href="javascript:;" class="btn btn-xs btn-status ' + (value == 0 ? 'btn-danger' : 'btn-success') + '" title="点击切换" data-table-id="table" style="margin-right: 4px;font-size: 90%;">' + (value == 0 ? '禁用(点击启用)' : '启用(点击禁用)') + '</a>';
                  },
                  test:function (value, row, index) {
                      return '<a href="fastflow/flow/message/test?id='+ row.id +'" class="btn btn-xs btn-success btn-dialog btn-test" title="发送测试消息" style="margin-right: 4px;font-size: 90%;"><i class="fa fa-envelope"></i> 发送测试消息</a>';
                  }
              },
              events: {
                  status: {
                      'click .btn-status': function (e, value, row, index) {
                          e.stopPropagation();
                          e.preventDefault();
                          var that = this;
                          var top = $(that).offset().top - $(window).scrollTop();
                          var left = $(that).offset().left - $(window).scrollLeft() - 260;
                          if (top + 154 > $(window).height()) {
                              top = top - 154;
                          }
                          if ($(window).width() < 480) {
                              top = left = undefined;
                          }
                          var table = $(that).closest('table');
                          if (value == 0) {
                              $(that).data('params', {'status': 1});
                              Table.api.multi(undefined, row['id'], table, that);
                          } else {
                              $(that).data('params', {'status': 0});
                              Layer.confirm(
                                  __('确定禁用吗?'),
                                  {
                                      icon: 3,
                                      title: __('Warning'),
                                      offset: [top, left],
                                      shadeClose: true,
                                      btn: [__('OK'), __('Cancel')]
                                  },
                                  function (index) {
                                      var options = table.bootstrapTable('getOptions');
                                      Table.api.multi(undefined, row['id'], table, that);
                                      Layer.close(index);
                                  }
                              );
                          }
  
                      }
                  },
              },
              createEditor: function () {
                  window.ispreview = false;
                  require.config({
                      paths:{
                          'htmlembedded':"../addons/fastflow/plugins/codemirror/mode/htmlembedded/htmlembedded",
                      },
                      shim: {
                          'htmlembedded':['css!../addons/fastflow/plugins/codemirror/lib/codemirror.css','css!../addons/fastflow/plugins/codemirror/theme/material.css'],
                      }
                  });
                  require(['htmlembedded'], function (CodeMirror) {
                      var editor = CodeMirror.fromTextArea(document.getElementById("templet"), {
                          lineNumbers: true,
                          indentUnit: 4,
                          indentWithTabs: true,
                          styleActiveLine: true,
                          mode: 'htmlmixed',
                          theme: 'material',
                          autoCloseBrackets: true,
                          foldGutter: true,
                          autoMatchParens: true
                      });
                      $('.btn-save').click(function () {
                          editor.save();
                          $('.btn-embossed').trigger('click');
                          return false;
                      });
                      $('.btn-linewrapping').click(function () {
                          var lineWrapping = editor.getOption('lineWrapping');
                          editor.setOption('lineWrapping',!lineWrapping);
                      });
                      $('.btn-linenumbers').click(function () {
                          var lineNumbers = editor.getOption('lineNumbers');
                          editor.setOption('lineNumbers',!lineNumbers);
                      });
                      $('.btn-preview').click(function () {
                          if (window.ispreview === false){
                              editor.save();
                              var content = $('#templet').val();
                              $('.CodeMirror').addClass('hidden');
                              $('#preview').removeClass('hidden').contents().find('body').html(content);
                              $('.btn-preview-text').html('编辑器');
                          }
                          else{
                              $('.CodeMirror').removeClass('hidden');
                              $('#preview').addClass('hidden');
                              $('.btn-preview-text').html('预览');
                          }
                          window.ispreview = !window.ispreview;
                      });
                  });
              }
          }
      };
      return Controller;
  });