manuscript.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
  2. var current_fs, next_fs, previous_fs; //fieldsets
  3. var left, opacity, scale; //fieldset properties which we will animate
  4. var animating; //flag to prevent quick multi-click glitches
  5. //设置弹窗宽高
  6. Fast.config.openArea = ['80%', '80%'];
  7. var Controller = {
  8. index: function () {
  9. // 初始化表格参数配置
  10. Table.api.init({
  11. extend: {
  12. index_url: 'cms/manuscript/index' + location.search,
  13. add_url: '',
  14. edit_url: 'cms/manuscript/edit',
  15. del_url: 'cms/manuscript/del',
  16. email_url: 'cms/manuscript/email',
  17. multi_url: 'cms/manuscript/multi',
  18. table: 'cms_manuscript',
  19. }
  20. });
  21. var table = $("#table");
  22. // 初始化表格
  23. table.bootstrapTable({
  24. url: $.fn.bootstrapTable.defaults.extend.index_url,
  25. pk: 'id',
  26. sortName: 'id',
  27. fixedColumns: true,
  28. fixedRightNumber: 1,
  29. columns: [
  30. [
  31. {checkbox: true},
  32. {field: 'id', title: __('Id')},
  33. {field: 'user.nickname', title: __('User_id'), operate: 'like'},
  34. {field: 'title', title: __('Title'), operate: 'like'},
  35. {field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
  36. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  37. {field: 'status', title: __('Status'), searchList: Config.site_manuscript_status , formatter: Table.api.formatter.status},
  38. {
  39. field: 'operate',
  40. title: __('Operate'),
  41. clickToSelect: false,
  42. table: table,
  43. events: Table.api.events.operate,
  44. formatter: function (value, row, index) {
  45. var that = $.extend({}, this);
  46. var table = $(this.table).clone(true);
  47. that.table = table;
  48. return Table.api.formatter.operate.call(that, value, row, index);
  49. },
  50. buttons:[
  51. {
  52. name: 'email',
  53. title: __('Send email'),
  54. text: __('Send email'),
  55. classname: 'btn btn-xs btn-info btn-dialog',
  56. icon: 'fa fa-envelope',
  57. url: $.fn.bootstrapTable.defaults.extend.email_url,
  58. },
  59. {
  60. name: 'editor',
  61. classname: 'btn btn-xs btn-primary btn-dialog',
  62. icon: 'fa fa-user-circle-o',
  63. title: __('Assign chief'),
  64. text: __('Assign chief'),
  65. url: function (row) {
  66. return 'cms/manuscript/edit_chief?ids=' + row.id;
  67. },
  68. callback: function (data) {
  69. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  70. },
  71. },
  72. {
  73. name: 'comments',
  74. classname: 'btn btn-xs btn-warning btn-dialog',
  75. icon: 'fa fa-list',
  76. title: __('Manuscript comments'),
  77. text: __('Manuscript comments'),
  78. url: function (row) {
  79. return 'cms/manuscript/comments?ids=' + row.id;
  80. },
  81. callback: function (data) {
  82. Layer.alert("接收到回传数据:" + JSON.stringify(data), {title: "回传数据"});
  83. },
  84. }
  85. ]
  86. }
  87. ]
  88. ]
  89. });
  90. // 为表格绑定事件
  91. Table.api.bindevent(table);
  92. },
  93. add: function () {
  94. var validName = false;
  95. //绑定表单事件
  96. Form.api.bindevent($("form[role=form]"));
  97. //验证触发
  98. $("form[role=form]").on('validation', function(e, content){
  99. var form = this;
  100. // form 中是否所有字段都验证通过
  101. if (content.id == 'name') {
  102. validName = content.isValid;
  103. }
  104. });
  105. var step = 1;
  106. $(".next").click(function() {
  107. if(animating) return false;
  108. animating = true;
  109. current_fs = $(this).parent().parent();
  110. next_fs = $(this).parent().parent().next();
  111. //activate next step on progressbar using the index of next_fs
  112. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  113. step += 1;
  114. //show the next fieldset
  115. next_fs.show();
  116. //hide the current fieldset with style
  117. current_fs.animate({opacity: 0}, {
  118. step: function(now, mx) {
  119. //as the opacity of current_fs reduces to 0 - stored in "now"
  120. //1. scale current_fs down to 80%
  121. scale = 1 - (1 - now) * 0.2;
  122. //2. bring next_fs from the right(50%)
  123. left = (now * 50)+"%";
  124. //3. increase opacity of next_fs to 1 as it moves in
  125. opacity = 1 - now;
  126. current_fs.css({
  127. 'transform': 'scale('+scale+')',
  128. 'position': 'absolute'
  129. });
  130. next_fs.css({'left': left, 'opacity': opacity});
  131. },
  132. duration: 800,
  133. complete: function(){
  134. current_fs.hide();
  135. animating = false;
  136. },
  137. //this comes from the custom easing plugin
  138. //easing: 'easeInOutBack'
  139. });
  140. });
  141. $(".previous").click(function() {
  142. if(animating) return false;
  143. animating = true;
  144. current_fs = $(this).parent().parent();
  145. previous_fs = $(this).parent().parent().prev();
  146. //de-activate current step on progressbar
  147. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  148. step -= 1;
  149. //show the previous fieldset
  150. previous_fs.show();
  151. //hide the current fieldset with style
  152. current_fs.animate({opacity: 0}, {
  153. step: function(now, mx) {
  154. //as the opacity of current_fs reduces to 0 - stored in "now"
  155. //1. scale previous_fs from 80% to 100%
  156. scale = 0.8 + (1 - now) * 0.2;
  157. //2. take current_fs to the right(50%) - from 0%
  158. left = ((1-now) * 50)+"%";
  159. //3. increase opacity of previous_fs to 1 as it moves in
  160. opacity = 1 - now;
  161. current_fs.css({'left': left});
  162. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  163. },
  164. duration: 800,
  165. complete: function(){
  166. current_fs.hide();
  167. animating = false;
  168. },
  169. //this comes from the custom easing plugin
  170. //easing: 'easeInOutBack'
  171. });
  172. });
  173. Controller.api.bindevent();
  174. },
  175. edit: function () {
  176. var validName = false;
  177. //绑定表单事件
  178. Form.api.bindevent($("form[role=form]"));
  179. //验证触发
  180. $("form[role=form]").on('validation', function(e, content){
  181. var form = this;
  182. // form 中是否所有字段都验证通过
  183. if (content.id == 'name') {
  184. validName = content.isValid;
  185. }
  186. });
  187. var step = 1;
  188. $(".next").click(function() {
  189. if(animating) return false;
  190. animating = true;
  191. current_fs = $(this).parent().parent();
  192. next_fs = $(this).parent().parent().next();
  193. //activate next step on progressbar using the index of next_fs
  194. $("#progressbar li").eq($("fieldset").index(next_fs)).addClass("active");
  195. step += 1;
  196. //show the next fieldset
  197. next_fs.show();
  198. //hide the current fieldset with style
  199. current_fs.animate({opacity: 0}, {
  200. step: function(now, mx) {
  201. //as the opacity of current_fs reduces to 0 - stored in "now"
  202. //1. scale current_fs down to 80%
  203. scale = 1 - (1 - now) * 0.2;
  204. //2. bring next_fs from the right(50%)
  205. left = (now * 50)+"%";
  206. //3. increase opacity of next_fs to 1 as it moves in
  207. opacity = 1 - now;
  208. current_fs.css({
  209. 'transform': 'scale('+scale+')',
  210. 'position': 'absolute'
  211. });
  212. next_fs.css({'left': left, 'opacity': opacity});
  213. },
  214. duration: 800,
  215. complete: function(){
  216. current_fs.hide();
  217. animating = false;
  218. },
  219. //this comes from the custom easing plugin
  220. //easing: 'easeInOutBack'
  221. });
  222. });
  223. $(".previous").click(function() {
  224. if(animating) return false;
  225. animating = true;
  226. current_fs = $(this).parent().parent();
  227. previous_fs = $(this).parent().parent().prev();
  228. //de-activate current step on progressbar
  229. $("#progressbar li").eq($("fieldset").index(current_fs)).removeClass("active");
  230. step -= 1;
  231. //show the previous fieldset
  232. previous_fs.show();
  233. //hide the current fieldset with style
  234. current_fs.animate({opacity: 0}, {
  235. step: function(now, mx) {
  236. //as the opacity of current_fs reduces to 0 - stored in "now"
  237. //1. scale previous_fs from 80% to 100%
  238. scale = 0.8 + (1 - now) * 0.2;
  239. //2. take current_fs to the right(50%) - from 0%
  240. left = ((1-now) * 50)+"%";
  241. //3. increase opacity of previous_fs to 1 as it moves in
  242. opacity = 1 - now;
  243. current_fs.css({'left': left});
  244. previous_fs.css({'transform': 'scale('+scale+')', 'opacity': opacity});
  245. },
  246. duration: 800,
  247. complete: function(){
  248. current_fs.hide();
  249. animating = false;
  250. },
  251. //this comes from the custom easing plugin
  252. //easing: 'easeInOutBack'
  253. });
  254. });
  255. // 关闭弹窗
  256. $(document).on('click', '.submit-button', function () {
  257. Fast.api.close();
  258. });
  259. Controller.api.bindevent();
  260. },
  261. edit_chief: function () {
  262. Form.api.bindevent($("form[role=form]"));
  263. Controller.api.bindevent();
  264. },
  265. comments: function () {
  266. // 初始化表格参数配置
  267. Table.api.init({
  268. extend: {
  269. index_url: 'cms/manuscript/comments' + location.search,
  270. table: 'cms_manuscript_comments',
  271. }
  272. });
  273. var table = $("#table");
  274. // 初始化表格
  275. table.bootstrapTable({
  276. url: $.fn.bootstrapTable.defaults.extend.index_url,
  277. pk: 'id',
  278. sortName: 'id',
  279. fixedColumns: true,
  280. fixedRightNumber: 1,
  281. columns: [
  282. [
  283. {checkbox: true},
  284. {field: 'id', title: __('Id')},
  285. {field: 'user.nickname', title: __('User_id'), operate: 'like'},
  286. {field: 'manuscript.title', title: __('Title'), operate: 'like'},
  287. {field: 'recommendation', title: __('Recommendation'), operate: 'like', formatter: Table.api.formatter.flag},
  288. {field: 'type', title: __('Type'), searchList: Config.site_type_list},
  289. {field: 'createtime', title: __('Createtime'), operate: 'RANGE', addclass: 'datetimerange', formatter: Table.api.formatter.datetime},
  290. {
  291. field: 'operate',
  292. title: __('Operate'),
  293. clickToSelect: false,
  294. table: table,
  295. events: Table.api.events.operate,
  296. formatter: function (value, row, index) {
  297. var that = $.extend({}, this);
  298. var table = $(this.table).clone(true);
  299. that.table = table;
  300. return Table.api.formatter.operate.call(that, value, row, index);
  301. },
  302. buttons:[
  303. {
  304. name: 'details',
  305. classname: 'btn btn-xs btn-warning btn-dialog',
  306. icon: 'fa fa-list',
  307. title: __('详情'),
  308. url: function (row) {
  309. return 'cms/manuscript/comments_detail?ids=' + row.id;
  310. },
  311. }
  312. ]
  313. }
  314. ]
  315. ]
  316. });
  317. // 为表格绑定事件
  318. Table.api.bindevent(table);
  319. },
  320. comments_detail: function () {
  321. Form.api.bindevent($("form[role=form]"));
  322. // 关闭弹窗
  323. $(document).on('click', '.btn-close', function () {
  324. Fast.api.close();
  325. });
  326. },
  327. email: function () {
  328. Form.api.bindevent($("form[role=form]"));
  329. Controller.api.bindevent();
  330. },
  331. api: {
  332. bindevent: function () {
  333. }
  334. }
  335. };
  336. return Controller;
  337. });