archives.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
  2. //设置弹窗宽高
  3. Fast.config.openArea = ['80%', '80%'];
  4. var Controller = {
  5. index: function () {
  6. // 初始化表格参数配置
  7. Table.api.init({
  8. extend: {
  9. index_url: 'cms/archives/index',
  10. add_url: 'cms/archives/add',
  11. edit_url: 'cms/archives/edit',
  12. del_url: 'cms/archives/del',
  13. multi_url: 'cms/archives/multi',
  14. dragsort_url: '',
  15. table: 'cms_archives',
  16. }
  17. });
  18. var table = $("#table");
  19. //在表格内容渲染完成后回调的事件
  20. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  21. //当为新选项卡中打开时
  22. if (Config.cms.archiveseditmode == 'addtabs') {
  23. $(".btn-editone", this)
  24. .off("click")
  25. .removeClass("btn-editone")
  26. .addClass("btn-addtabs")
  27. .prop("title", __('Edit'));
  28. }
  29. });
  30. //当双击单元格时
  31. table.on('dbl-click-row.bs.table', function (e, row, element, field) {
  32. $(".btn-addtabs", element).trigger("click");
  33. });
  34. // 初始化表格
  35. table.bootstrapTable({
  36. url: $.fn.bootstrapTable.defaults.extend.index_url,
  37. pk: 'id',
  38. sortName: 'weigh DESC,id DESC',
  39. searchFormVisible: Fast.api.query("model_id") ? true : false,
  40. fixedColumns: true,
  41. fixedRightNumber: 1,
  42. columns: [
  43. [
  44. {checkbox: true},
  45. {field: 'id', title: __('Id'), sortable: true},
  46. {
  47. field: 'user_id',
  48. title: __('User_id'),
  49. visible: false,
  50. addclass: 'selectpage',
  51. extend: 'data-source="user/user/index" data-field="nickname"',
  52. operate: '=',
  53. formatter: Table.api.formatter.search
  54. },
  55. {
  56. field: 'admin_id',
  57. title: __('Admin_id'),
  58. visible: false,
  59. addclass: 'selectpage',
  60. extend: 'data-source="auth/admin/selectpage" data-field="nickname"',
  61. operate: '=',
  62. formatter: Table.api.formatter.search
  63. },
  64. {
  65. field: 'channel_id',
  66. title: __('Channel_id'),
  67. visible: false,
  68. addclass: 'selectpage',
  69. extend: 'data-source="cms/channel/index" data-field="name"',
  70. operate: 'in',
  71. formatter: Table.api.formatter.search
  72. },
  73. {
  74. field: 'channel_ids',
  75. title: __('Channel_ids'),
  76. visible: false,
  77. addclass: 'selectpage',
  78. extend: 'data-source="cms/channel/index" data-field="name"',
  79. operate: 'find_in_set',
  80. formatter: Table.api.formatter.search
  81. },
  82. {
  83. field: 'channel.name',
  84. title: __('Channel'),
  85. operate: false,
  86. formatter: function (value, row, index) {
  87. return '<a href="javascript:;" class="searchit" data-field="channel_id" data-value="' + row.channel_id + '">' + value + '</a>';
  88. }
  89. },
  90. {
  91. field: 'model_id', title: __('Model'), visible: false, align: 'left', addclass: "selectpage", extend: "data-source='cms/modelx/index' data-field='name'"
  92. },
  93. {
  94. field: 'title', title: __('Title'), align: 'left', operate: 'like', customField: 'flag', formatter: function (value, row, index) {
  95. return '<div class="archives-title"><a href="' + row.url + '" target="_blank"><span style="color:' + (row.style_color ? row.style_color : 'inherit') + ';font-weight:' + (row.style_bold ? 'bold' : 'normal') + '">' + value + '</span></a></div>' +
  96. '<div class="archives-label">' + Table.api.formatter.flag.call(this, row['flag'], row, index) + '</div>';
  97. }
  98. },
  99. {field: 'flag', title: __('Flag'), operate: 'find_in_set', visible: false, searchList: Config.flagList, formatter: Table.api.formatter.flag},
  100. {
  101. field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: function (value, row, index) {
  102. value = value == null || value.length === 0 ? '' : value.toString();
  103. value = value ? value : '/assets/addons/cms/img/noimage.png';
  104. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  105. return '<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>';
  106. }
  107. },
  108. {field: 'price', title: __('Price'), operate: 'BETWEEN', sortable: true},
  109. {field: 'views', title: __('Views'), operate: 'BETWEEN', sortable: true},
  110. {
  111. field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
  112. return '<a href="javascript:" data-url="cms/comment/index?type=archives&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
  113. }
  114. },
  115. {field: 'weigh', title: __('Weigh'), operate: false, sortable: true},
  116. {
  117. field: 'createtime',
  118. title: __('Createtime'),
  119. visible: false,
  120. operate: 'RANGE',
  121. addclass: 'datetimerange',
  122. formatter: Table.api.formatter.datetime,
  123. autocomplete: false
  124. },
  125. {
  126. field: 'updatetime',
  127. title: __('Updatetime'),
  128. visible: false,
  129. operate: 'RANGE',
  130. addclass: 'datetimerange',
  131. formatter: Table.api.formatter.datetime,
  132. autocomplete: false
  133. },
  134. {
  135. field: 'publishtime',
  136. title: __('Publishtime'),
  137. sortable: true,
  138. operate: 'RANGE',
  139. addclass: 'datetimerange',
  140. formatter: Table.api.formatter.datetime,
  141. datetimeFormat: "YYYY-MM-DD",
  142. autocomplete: false
  143. },
  144. {field: 'status', title: __('Status'), searchList: {"normal": __('Status normal'), "hidden": __('Status hidden'), "rejected": __('Status rejected'), "pulloff": __('Status pulloff')}, formatter: Table.api.formatter.status},
  145. {
  146. field: 'operate',
  147. title: __('Operate'),
  148. table: table,
  149. events: Table.api.events.operate,
  150. formatter: Table.api.formatter.operate
  151. }
  152. ]
  153. ]
  154. });
  155. // 为表格绑定事件
  156. Table.api.bindevent(table);
  157. var url = '';
  158. //当为新选项卡中打开时
  159. if (Config.cms.archiveseditmode == 'addtabs') {
  160. url = (url + '?ids=' + $(".commonsearch-table input[name=channel_id]").val());
  161. }
  162. $(".btn-add").off("click").on("click", function () {
  163. var url = 'cms/archives/add?channel=' + $(".commonsearch-table input[name=channel_id]").val();
  164. //当为新选项卡中打开时
  165. if (Config.cms.archiveseditmode == 'addtabs') {
  166. Fast.api.addtabs(url, __('Add'));
  167. } else {
  168. Fast.api.open(url, __('Add'), $(this).data() || {});
  169. }
  170. return false;
  171. });
  172. $(document).on("click", "a.btn-channel", function () {
  173. $("#archivespanel").toggleClass("col-md-9", $("#channelbar").hasClass("hidden"));
  174. $("#channelbar").toggleClass("hidden");
  175. });
  176. $(document).on("click", "a.btn-setspecial", function () {
  177. var ids = Table.api.selectedids(table);
  178. Layer.open({
  179. title: __('Set special'),
  180. content: Template("specialtpl", {}),
  181. btn: [__('Ok')],
  182. yes: function (index, layero) {
  183. var special_id = $("select[name='special']", layero).val();
  184. if (special_id == 0) {
  185. Toastr.error(__('Please select special'));
  186. return;
  187. }
  188. Fast.api.ajax({
  189. url: "cms/archives/special/ids/" + ids.join(","),
  190. type: "post",
  191. data: {special_id: special_id},
  192. }, function () {
  193. table.bootstrapTable('refresh', {});
  194. Layer.close(index);
  195. });
  196. },
  197. success: function (layero, index) {
  198. }
  199. });
  200. });
  201. require(['jstree'], function () {
  202. //全选和展开
  203. $(document).on("click", "#checkall", function () {
  204. $("#channeltree").jstree($(this).prop("checked") ? "check_all" : "uncheck_all");
  205. });
  206. $(document).on("click", "#expandall", function () {
  207. $("#channeltree").jstree($(this).prop("checked") ? "open_all" : "close_all");
  208. });
  209. $('#channeltree').on("changed.jstree", function (e, data) {
  210. $(".commonsearch-table input[name=channel_id]").val(data.selected.join(","));
  211. table.bootstrapTable('refresh', {});
  212. return false;
  213. });
  214. $('#channeltree').jstree({
  215. "themes": {
  216. "stripes": true
  217. },
  218. "checkbox": {
  219. "keep_selected_style": false,
  220. },
  221. "types": {
  222. "channel": {
  223. "icon": false,
  224. },
  225. "list": {
  226. "icon": false,
  227. },
  228. "link": {
  229. "icon": false,
  230. },
  231. "disabled": {
  232. "check_node": false,
  233. "uncheck_node": false
  234. }
  235. },
  236. 'plugins': ["types", "checkbox"],
  237. "core": {
  238. "multiple": true,
  239. 'check_callback': true,
  240. "data": Config.channelList
  241. }
  242. });
  243. });
  244. $(document).on('click', '.btn-move', function () {
  245. var ids = Table.api.selectedids(table);
  246. Layer.open({
  247. title: __('Move'),
  248. content: Template("channeltpl", {}),
  249. btn: [__('Move')],
  250. yes: function (index, layero) {
  251. var channel_id = $("select[name='channel']", layero).val();
  252. if (channel_id == 0) {
  253. Toastr.error(__('Please select channel'));
  254. return;
  255. }
  256. Fast.api.ajax({
  257. url: "cms/archives/move/ids/" + ids.join(","),
  258. type: "post",
  259. data: {channel_id: channel_id},
  260. }, function () {
  261. table.bootstrapTable('refresh', {});
  262. Layer.close(index);
  263. });
  264. },
  265. success: function (layero, index) {
  266. }
  267. });
  268. });
  269. },
  270. content: function () {
  271. // 初始化表格参数配置
  272. Table.api.init({
  273. extend: {
  274. index_url: 'cms/archives/content/model_id/' + Config.model_id,
  275. add_url: '',
  276. edit_url: 'cms/archives/edit',
  277. del_url: 'cms/archives/del',
  278. multi_url: '',
  279. dragsort_url: '',
  280. table: '',
  281. }
  282. });
  283. var table = $("#table");
  284. //在表格内容渲染完成后回调的事件
  285. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  286. //当为新选项卡中打开时
  287. if (Config.cms.archiveseditmode == 'addtabs') {
  288. $(".btn-editone", this)
  289. .off("click")
  290. .removeClass("btn-editone")
  291. .addClass("btn-addtabs")
  292. .prop("title", __('Edit'));
  293. }
  294. });
  295. //默认字段
  296. var columns = [
  297. {checkbox: true},
  298. //这里因为涉及到关联多个表,因为用了两个字段来操作,一个隐藏,一个搜索
  299. {field: 'main.id', title: __('Id'), visible: false},
  300. {field: 'id', title: __('Id'), operate: false},
  301. {field: 'user_id', title: __('User_id'), formatter: Table.api.formatter.search},
  302. {
  303. field: 'channel_id',
  304. title: __('Channel_id'),
  305. addclass: 'selectpage',
  306. extend: 'data-source="cms/channel/index"',
  307. formatter: Table.api.formatter.search
  308. },
  309. {field: 'channel_name', title: __('Channel_name'), operate: false},
  310. {
  311. field: 'title', title: __('Title'), align: 'left', customField: 'flag', formatter: function (value, row, index) {
  312. return '<div class="archives-title"><a href="' + row.url + '" target="_blank"><span style="color:' + (row.style_color ? row.style_color : 'inherit') + ';font-weight:' + (row.style_bold ? 'bold' : 'normal') + '">' + value + '</span></a></div>' +
  313. '<div class="archives-label">' + Table.api.formatter.flag.call(this, row['flag'], row, index) + '</div>';
  314. }
  315. },
  316. {field: 'flag', title: __('Flag'), operate: 'find_in_set', visible: false, searchList: Config.flagList, formatter: Table.api.formatter.flag},
  317. {
  318. field: 'image', title: __('Image'), operate: false, events: Table.api.events.image, formatter: function (value, row, index) {
  319. value = value == null || value.length === 0 ? '' : value.toString();
  320. value = value ? value : '/assets/addons/cms/img/noimage.png';
  321. var classname = typeof this.classname !== 'undefined' ? this.classname : 'img-sm img-center';
  322. return '<a href="javascript:"><img class="' + classname + '" src="' + Fast.api.cdnurl(value) + '" /></a>';
  323. }
  324. },
  325. {field: 'views', title: __('Views'), operate: 'BETWEEN', sortable: true},
  326. {
  327. field: 'comments', title: __('Comments'), operate: 'BETWEEN', sortable: true, formatter: function (value, row, index) {
  328. return '<a href="javascript:" data-url="cms/comment/index?type=archives&aid=' + row['id'] + '" title="评论列表" class="dialogit">' + value + '</a>';
  329. }
  330. }
  331. ];
  332. //动态追加字段
  333. $.each(Config.fields, function (i, j) {
  334. var data = {field: j.field, title: j.title, table: table, operate: (j.type === 'number' ? '=' : 'like')};
  335. //如果是图片,加上formatter
  336. if (j.type == 'image') {
  337. data.events = Table.api.events.image;
  338. data.formatter = Table.api.formatter.image;
  339. } else if (j.type == 'images') {
  340. data.events = Table.api.events.image;
  341. data.formatter = Table.api.formatter.images;
  342. } else if (j.type == 'radio' || j.type == 'checkbox' || j.type == 'select' || j.type == 'selects') {
  343. data.formatter = Controller.api.formatter.content;
  344. data.extend = j.content;
  345. data.searchList = j.content;
  346. } else {
  347. data.formatter = Table.api.formatter.content;
  348. }
  349. columns.push(data);
  350. });
  351. //追加操作字段
  352. columns.push({
  353. field: 'operate',
  354. title: __('Operate'),
  355. table: table,
  356. width: '80px',
  357. events: Table.api.events.operate,
  358. formatter: Table.api.formatter.operate
  359. });
  360. // 初始化表格
  361. table.bootstrapTable({
  362. url: $.fn.bootstrapTable.defaults.extend.index_url,
  363. pk: 'id',
  364. sortName: 'id',
  365. fixedColumns: true,
  366. fixedRightNumber: 1,
  367. columns: columns
  368. });
  369. // 为表格绑定事件
  370. Table.api.bindevent(table);
  371. },
  372. diyform: function () {
  373. // 初始化表格参数配置
  374. Table.api.init({
  375. extend: {
  376. index_url: 'cms/archives/diyform/diyform_id/' + Config.diyform_id,
  377. add_url: '',
  378. edit_url: 'cms/archives/edit',
  379. del_url: 'cms/archives/del',
  380. multi_url: '',
  381. table: '',
  382. }
  383. });
  384. var table = $("#table");
  385. //在表格内容渲染完成后回调的事件
  386. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  387. $(".btn-editone", this)
  388. .off("click")
  389. .removeClass("btn-editone")
  390. .addClass("btn-addtabs")
  391. .prop("title", __('Edit'));
  392. });
  393. //默认字段
  394. var columns = [
  395. {checkbox: true},
  396. {field: 'id', title: __('Id'), operate: false},
  397. ];
  398. //动态追加字段
  399. $.each(Config.fields, function (i, j) {
  400. var data = {field: j.field, title: j.title, operate: 'like'};
  401. //如果是图片,加上formatter
  402. if (j.type == 'image') {
  403. data.formatter = Table.api.formatter.image;
  404. } else if (j.type == 'images') {
  405. data.formatter = Table.api.formatter.images;
  406. } else if (j.type == 'radio' || j.type == 'check' || j.type == 'select' || j.type == 'selects') {
  407. data.formatter = Controller.api.formatter.content;
  408. data.extend = j.content;
  409. } else {
  410. data.formatter = Table.api.formatter.content;
  411. }
  412. columns.push(data);
  413. });
  414. //追加操作字段
  415. columns.push({
  416. field: 'operate',
  417. title: __('Operate'),
  418. table: table,
  419. events: Table.api.events.operate,
  420. formatter: Table.api.formatter.operate
  421. });
  422. // 初始化表格
  423. table.bootstrapTable({
  424. url: $.fn.bootstrapTable.defaults.extend.index_url,
  425. pk: 'id',
  426. sortName: 'id',
  427. columns: columns
  428. })
  429. ;
  430. // 为表格绑定事件
  431. Table.api.bindevent(table);
  432. },
  433. recyclebin: function () {
  434. // 初始化表格参数配置
  435. Table.api.init({
  436. extend: {
  437. 'dragsort_url': ''
  438. }
  439. });
  440. var table = $("#table");
  441. // 初始化表格
  442. table.bootstrapTable({
  443. url: 'cms/archives/recyclebin',
  444. pk: 'id',
  445. sortName: 'weigh',
  446. columns: [
  447. [
  448. {checkbox: true},
  449. {field: 'id', title: __('Id')},
  450. {field: 'title', title: __('Title'), align: 'left', operate: 'like'},
  451. {field: 'image', title: __('Image'), operate: false, formatter: Table.api.formatter.image},
  452. {
  453. field: 'deletetime',
  454. title: __('Deletetime'),
  455. operate: 'RANGE',
  456. addclass: 'datetimerange',
  457. formatter: Table.api.formatter.datetime
  458. },
  459. {
  460. field: 'operate',
  461. width: '130px',
  462. title: __('Operate'),
  463. table: table,
  464. events: Table.api.events.operate,
  465. buttons: [
  466. {
  467. name: 'Restore',
  468. text: __('Restore'),
  469. classname: 'btn btn-xs btn-info btn-ajax btn-restoreit',
  470. icon: 'fa fa-rotate-left',
  471. url: 'cms/archives/restore',
  472. refresh: true
  473. },
  474. {
  475. name: 'Destroy',
  476. text: __('Destroy'),
  477. classname: 'btn btn-xs btn-danger btn-ajax btn-destroyit',
  478. icon: 'fa fa-times',
  479. url: 'cms/archives/destroy',
  480. refresh: true
  481. }
  482. ],
  483. formatter: Table.api.formatter.operate
  484. }
  485. ]
  486. ]
  487. });
  488. // 为表格绑定事件
  489. Table.api.bindevent(table);
  490. },
  491. add: function () {
  492. var last_channel_id = localStorage.getItem('last_channel_id');
  493. var channel = Fast.api.query("channel");
  494. if (channel) {
  495. var channelIds = channel.split(",");
  496. $(channelIds).each(function (i, j) {
  497. if ($("#c-channel_id option[value='" + j + "']:disabled").size() > 0) {
  498. return true;
  499. }
  500. last_channel_id = j;
  501. return false;
  502. });
  503. }
  504. if (last_channel_id) {
  505. $("#c-channel_id option[value='" + last_channel_id + "']").prop("selected", true);
  506. }
  507. Controller.api.bindevent();
  508. $("#c-channel_id").trigger("change");
  509. },
  510. edit: function () {
  511. Controller.api.bindevent();
  512. $("#c-channel_id").trigger("change");
  513. },
  514. api: {
  515. formatter: {
  516. content: function (value, row, index) {
  517. var extend = this.extend;
  518. if (!value) {
  519. return '';
  520. }
  521. var valueArr = value.toString().split(/\,/);
  522. var result = [];
  523. $.each(valueArr, function (i, j) {
  524. result.push(typeof extend[j] !== 'undefined' ? extend[j] : j);
  525. });
  526. return result.join(',');
  527. }
  528. },
  529. bindevent: function () {
  530. var refreshStyle = function () {
  531. var style = [];
  532. if ($(".btn-bold").hasClass("active")) {
  533. style.push("b");
  534. }
  535. if ($(".btn-color").hasClass("active")) {
  536. style.push($(".btn-color").data("color"));
  537. }
  538. $("input[name='row[style]']").val(style.join("|"));
  539. };
  540. var insertHtml = function (html) {
  541. if (typeof KindEditor !== 'undefined') {
  542. KindEditor.insertHtml("#c-content", html);
  543. } else if (typeof UM !== 'undefined' && typeof UM.list["c-content"] !== 'undefined') {
  544. UM.list["c-content"].execCommand("insertHtml", html);
  545. } else if (typeof UE !== 'undefined' && typeof UE.list["c-content"] !== 'undefined') {
  546. UE.list["c-content"].execCommand("insertHtml", html);
  547. } else if ($("#c-content").data("summernote")) {
  548. $('#c-content').summernote('pasteHTML', html);
  549. } else if (typeof Simditor !== 'undefined' && typeof Simditor.list['c-content'] !== 'undefined') {
  550. Simditor.list['c-content'].setValue($('#c-content').val() + html);
  551. } else {
  552. Layer.open({
  553. content: "你的编辑器暂不支持插入HTML代码,请手动复制以下代码到你的编辑器" + "<textarea class='form-control' rows='5'>" + html + "</textarea>", title: "温馨提示"
  554. });
  555. }
  556. };
  557. $(document).on("click", ".btn-paytag", function () {
  558. insertHtml("##paidbegin##\n\n请替换付费标签内内容\n\n##paidend##");
  559. });
  560. $(document).on("click", ".btn-pagertag", function () {
  561. insertHtml("##pagebreak##");
  562. });
  563. require(['jquery-autocomplete'], function () {
  564. var search = $("#c-title");
  565. var form = search.closest("form");
  566. Template.helper("formatter", Table.api.formatter);
  567. search.autoComplete({
  568. minChars: 1,
  569. cache: false,
  570. menuClass: 'autocomplete-searchtitle',
  571. header: Template('headertpl', {}),
  572. footer: '',
  573. source: function (term, response) {
  574. try {
  575. xhr.abort();
  576. } catch (e) {
  577. }
  578. xhr = $.getJSON(search.data("suggestion-url"), {q: term}, function (data) {
  579. response($.isArray(data) ? data : []);
  580. });
  581. },
  582. renderItem: function (item, search) {
  583. search = search.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&');
  584. var regexp = new RegExp("(" + search.replace(/[\,|\u3000|\uff0c]/, ' ').split(' ').join('|') + ")", "gi");
  585. Template.helper("replace", function (value) {
  586. return value.replace(regexp, "<b>$1</b>");
  587. });
  588. return Template('itemtpl', {item: item, search: search, context: {operate: false, searchList: {"normal": __('Status normal'), "hidden": __('Status hidden'), "rejected": __('Status rejected'), "pulloff": __('Status pulloff')}}});
  589. },
  590. onSelect: function (e, term, item) {
  591. e.preventDefault();
  592. if (typeof callback === 'function') {
  593. callback.call(elem, term, item);
  594. } else {
  595. if ($(item).data("url")) {
  596. location.href = $(item).data("url");
  597. }
  598. return false;
  599. }
  600. }
  601. });
  602. });
  603. require(['jquery-colorpicker'], function () {
  604. $('.colorpicker').colorpicker({
  605. color: function () {
  606. var color = "#000000";
  607. var rgb = $("#c-title").css('color').match(/^rgb\(((\d+),\s*(\d+),\s*(\d+))\)$/);
  608. if (rgb) {
  609. color = rgb[1];
  610. }
  611. return color;
  612. }
  613. }, function (event, obj) {
  614. $("#c-title").css('color', '#' + obj.hex);
  615. $(event).addClass("active").data("color", '#' + obj.hex);
  616. refreshStyle();
  617. }, function (event) {
  618. $("#c-title").css('color', 'inherit');
  619. $(event).removeClass("active");
  620. refreshStyle();
  621. });
  622. });
  623. require(['jquery-tagsinput'], function () {
  624. //标签输入
  625. var elem = "#c-tags";
  626. var tags = $(elem);
  627. tags.tagsInput({
  628. width: 'auto',
  629. defaultText: '输入后空格确认',
  630. minInputWidth: 110,
  631. height: '36px',
  632. placeholderColor: '#999',
  633. onChange: function (row) {
  634. if (typeof callback === 'function') {
  635. } else {
  636. $(elem + "_addTag").focus();
  637. $(elem + "_tag").trigger("blur.autocomplete").focus();
  638. }
  639. },
  640. autocomplete: {
  641. url: 'cms/tag/autocomplete',
  642. minChars: 1,
  643. menuClass: 'autocomplete-tags'
  644. }
  645. });
  646. });
  647. //获取标题拼音
  648. var si;
  649. $(document).on("keyup", "#c-title", function () {
  650. var value = $(this).val();
  651. if (value != '' && !value.match(/\n/)) {
  652. clearTimeout(si);
  653. si = setTimeout(function () {
  654. Fast.api.ajax({
  655. loading: false,
  656. url: "cms/ajax/get_title_pinyin",
  657. data: {title: value, delimiter: "-"}
  658. }, function (data, ret) {
  659. $("#c-diyname").val(data.pinyin.substr(0, 100));
  660. return false;
  661. }, function (data, ret) {
  662. return false;
  663. });
  664. }, 200);
  665. }
  666. });
  667. $(document).on('click', '.btn-bold', function () {
  668. $("#c-title").toggleClass("text-bold", !$(this).hasClass("active"));
  669. $(this).toggleClass("text-bold active");
  670. refreshStyle();
  671. });
  672. $(document).on('change', '#c-channel_id', function () {
  673. var model = $("option:selected", this).attr("model");
  674. var value = $("option:selected", this).val();
  675. Fast.api.ajax({
  676. url: 'cms/archives/get_fields_html',
  677. data: {channel_id: value, archives_id: $("#archive-id").val()}
  678. }, function (data) {
  679. if ($("#extend").data("model") != model) {
  680. $("#extend").html(data.html).data("model", model);
  681. Form.api.bindevent($("#extend"));
  682. }
  683. return false;
  684. });
  685. localStorage.setItem('last_channel_id', $(this).val());
  686. $("#c-channel_ids option").prop("disabled", true);
  687. $("#c-channel_ids option[model!='" + model + "']").prop("selected", false);
  688. $("#c-channel_id option[model='" + model + "']:not([disabled])").each(function () {
  689. $("#c-channel_ids option[model='" + $(this).attr("model") + "'][value='" + $(this).attr("value") + "']").prop("disabled", false);
  690. });
  691. if ($("#c-channel_ids").data("selectpicker")) {
  692. $("#c-channel_ids").data("selectpicker").refresh();
  693. }
  694. });
  695. $(document).on("fa.event.appendfieldlist", ".downloadlist", function (a) {
  696. Form.events.plupload(this);
  697. $(".fachoose", this).off("click");
  698. Form.events.faselect(this);
  699. });
  700. //检测内容
  701. $(document).on("click", ".btn-legal", function (a) {
  702. Fast.api.ajax({
  703. url: "cms/ajax/check_content_islegal",
  704. data: {content: $("#c-content").val()}
  705. }, function (data, ret) {
  706. }, function (data, ret) {
  707. if ($.isArray(data)) {
  708. if (data.length > 1) {
  709. Layer.alert(__('Banned words') + ":" + data.join(","));
  710. } else {
  711. Layer.alert(ret.msg);
  712. }
  713. return false;
  714. }
  715. });
  716. });
  717. //提取关键字
  718. $(document).on("click", ".btn-keywords", function (a) {
  719. Fast.api.ajax({
  720. url: "cms/ajax/get_content_keywords",
  721. data: {title: $("#c-title").val(), tags: $("#c-tags").val(), content: $("#c-content").val()}
  722. }, function (data, ret) {
  723. $("#c-keywords").val(data.keywords);
  724. $("#c-description").val(data.description);
  725. });
  726. });
  727. //提取缩略图
  728. $(document).on("click", ".btn-getimage", function (a) {
  729. var image = $("<div>" + $("#c-content").val() + "</div>").find('img').first().attr('src');
  730. if (image) {
  731. var obj = $("#c-image");
  732. if (obj.val() != '') {
  733. Layer.confirm("缩略图已存在,是否替换?", {icon: 3}, function (index) {
  734. obj.val(image).trigger("change");
  735. layer.close(index);
  736. Toastr.success("提取成功");
  737. });
  738. } else {
  739. obj.val(image).trigger("change");
  740. Toastr.success("提取成功");
  741. }
  742. } else {
  743. Toastr.error("未找到任何图片");
  744. }
  745. return false;
  746. });
  747. //提取组图
  748. $(document).on("click", ".btn-getimages", function (a) {
  749. var image = $("<div>" + $("#c-content").val() + "</div>").find('img').first().attr('src');
  750. if (image) {
  751. var imageArr = [];
  752. $("<div>" + $("#c-content").val() + "</div>").find('img').each(function (i, j) {
  753. if (i > 3) {
  754. return false;
  755. }
  756. imageArr.push($(this).attr("src"));
  757. });
  758. image = imageArr.slice(0, 4).join(",");
  759. var obj = $("#c-images");
  760. if (obj.val() != '') {
  761. Layer.confirm("文章组图已存在,是否替换?", {icon: 3}, function (index) {
  762. obj.val(image).trigger("change");
  763. layer.close(index);
  764. Toastr.success("提取成功");
  765. });
  766. } else {
  767. obj.val(image).trigger("change");
  768. Toastr.success("提取成功");
  769. }
  770. } else {
  771. Toastr.error("未找到任何图片");
  772. }
  773. return false;
  774. });
  775. $.validator.config({
  776. rules: {
  777. diyname: function (element) {
  778. if (element.value.toString().match(/^\d+$/)) {
  779. return __('Can not be only digital');
  780. }
  781. if (!element.value.toString().match(/^[a-zA-Z0-9\-_]+$/)) {
  782. return __('Please input character or digital');
  783. }
  784. return $.ajax({
  785. url: 'cms/archives/check_element_available',
  786. type: 'POST',
  787. data: {id: $("#archive-id").val(), name: element.name, value: element.value},
  788. dataType: 'json'
  789. });
  790. },
  791. isnormal: function (element) {
  792. return $("#c-status").val() == 'normal' ? true : false;
  793. }
  794. }
  795. });
  796. var iscontinue = false;
  797. $(document).on("click", ".btn-continue", function () {
  798. iscontinue = true;
  799. $(this).prev().trigger("click");
  800. });
  801. Form.api.bindevent($("form[role=form]"), function () {
  802. if (iscontinue) {
  803. $(window).scrollTop(0);
  804. location.reload();
  805. top.window.Toastr.success(__('Operation completed'));
  806. return false;
  807. } else {
  808. if (Config.cms.archiveseditmode == 'addtabs') {
  809. var obj = top.window.$("ul.nav-addtabs li.active");
  810. top.window.Toastr.success(__('Operation completed'));
  811. top.window.$(".sidebar-menu a[url$='/cms/archives'][addtabs]").click();
  812. top.window.$(".sidebar-menu a[url$='/cms/archives'][addtabs]").dblclick();
  813. obj.find(".fa-remove").trigger("click");
  814. }
  815. }
  816. });
  817. }
  818. }
  819. };
  820. return Controller;
  821. });