archives.js 46 KB

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