archives.js 46 KB

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