addon.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
  2. var Controller = {
  3. index: function () {
  4. // 初始化表格参数配置
  5. Table.api.init({
  6. extend: {
  7. index_url: Config.api_url ? Config.api_url + '/addon/index' : "addon/downloaded",
  8. add_url: '',
  9. edit_url: '',
  10. del_url: '',
  11. multi_url: ''
  12. }
  13. });
  14. var table = $("#table");
  15. // 弹窗自适应宽高
  16. var area = Fast.config.openArea != undefined ? Fast.config.openArea : [$(window).width() > 800 ? '800px' : '95%', $(window).height() > 600 ? '600px' : '95%'];
  17. var switch_local = function () {
  18. if ($(".btn-switch.active").data("type") != "local") {
  19. Layer.confirm(__('Store not available tips'), {
  20. title: __('Warmtips'),
  21. btn: [__('Switch to the local'), __('Try to reload')]
  22. }, function (index) {
  23. layer.close(index);
  24. $(".panel .nav-tabs").hide();
  25. $(".toolbar > *:not(:first)").hide();
  26. $(".btn-switch[data-type='local']").trigger("click");
  27. }, function (index) {
  28. layer.close(index);
  29. table.bootstrapTable('refresh');
  30. });
  31. return false;
  32. }
  33. };
  34. table.on('load-success.bs.table', function (e, json) {
  35. if (json && typeof json.category != 'undefined' && $(".nav-category li").length == 2) {
  36. $.each(json.category, function (i, j) {
  37. $("<li><a href='javascript:;' data-id='" + j.id + "'>" + j.name + "</a></li>").insertBefore($(".nav-category li:last"));
  38. });
  39. }
  40. if (typeof json.rows === 'undefined' && typeof json.code != 'undefined') {
  41. switch_local();
  42. }
  43. });
  44. table.on('load-error.bs.table', function (e, status, res) {
  45. console.log(e, status, res);
  46. switch_local();
  47. });
  48. table.on('post-body.bs.table', function (e, settings, json, xhr) {
  49. var parenttable = table.closest('.bootstrap-table');
  50. var d = $(".fixed-table-toolbar", parenttable).find(".search input");
  51. d.off("keyup drop blur");
  52. d.on("keyup", function (e) {
  53. if (e.keyCode == 13) {
  54. var that = this;
  55. var options = table.bootstrapTable('getOptions');
  56. var queryParams = options.queryParams;
  57. options.pageNumber = 1;
  58. options.queryParams = function (params) {
  59. var params = queryParams(params);
  60. params.search = $(that).val();
  61. return params;
  62. };
  63. table.bootstrapTable('refresh', {});
  64. }
  65. });
  66. });
  67. Template.helper("Moment", Moment);
  68. Template.helper("addons", Config['addons']);
  69. $("#faupload-addon").data("params", function () {
  70. var userinfo = Controller.api.userinfo.get();
  71. return {
  72. uid: userinfo ? userinfo.id : '',
  73. token: userinfo ? userinfo.token : '',
  74. version: Config.faversion
  75. };
  76. });
  77. // 初始化表格
  78. table.bootstrapTable({
  79. url: $.fn.bootstrapTable.defaults.extend.index_url,
  80. pageSize: 50,
  81. queryParams: function (params) {
  82. var userinfo = Controller.api.userinfo.get();
  83. $.extend(params, {
  84. uid: userinfo ? userinfo.id : '',
  85. token: userinfo ? userinfo.token : '',
  86. domain: Config.domain,
  87. version: Config.faversion
  88. });
  89. return params;
  90. },
  91. columns: [
  92. [
  93. {field: 'id', title: 'ID', operate: false, visible: false},
  94. {
  95. field: 'home',
  96. title: __('Index'),
  97. width: '50px',
  98. formatter: Controller.api.formatter.home
  99. },
  100. {field: 'name', title: __('Name'), operate: false, visible: false, width: '120px'},
  101. {
  102. field: 'title',
  103. title: __('Title'),
  104. operate: 'LIKE',
  105. align: 'left',
  106. formatter: Controller.api.formatter.title
  107. },
  108. {field: 'intro', title: __('Intro'), operate: 'LIKE', align: 'left', class: 'visible-lg'},
  109. {
  110. field: 'author',
  111. title: __('Author'),
  112. operate: 'LIKE',
  113. width: '100px',
  114. formatter: Controller.api.formatter.author
  115. },
  116. {
  117. field: 'price',
  118. title: __('Price'),
  119. operate: 'LIKE',
  120. width: '100px',
  121. align: 'center',
  122. formatter: Controller.api.formatter.price
  123. },
  124. {
  125. field: 'downloads',
  126. title: __('Downloads'),
  127. operate: 'LIKE',
  128. width: '80px',
  129. align: 'center',
  130. formatter: Controller.api.formatter.downloads
  131. },
  132. {
  133. field: 'version',
  134. title: __('Version'),
  135. operate: 'LIKE',
  136. width: '80px',
  137. align: 'center',
  138. formatter: Controller.api.formatter.version
  139. },
  140. {
  141. field: 'toggle',
  142. title: __('Status'),
  143. width: '80px',
  144. formatter: Controller.api.formatter.toggle
  145. },
  146. {
  147. field: 'id',
  148. title: __('Operate'),
  149. table: table,
  150. formatter: Controller.api.formatter.operate,
  151. align: 'right'
  152. },
  153. ]
  154. ],
  155. responseHandler: function (res) {
  156. $.each(res.rows, function (i, j) {
  157. j.addon = typeof Config.addons[j.name] != 'undefined' ? Config.addons[j.name] : null;
  158. });
  159. return res;
  160. },
  161. dataType: 'jsonp',
  162. templateView: false,
  163. clickToSelect: false,
  164. search: true,
  165. showColumns: false,
  166. showToggle: false,
  167. showExport: false,
  168. showSearch: false,
  169. commonSearch: true,
  170. searchFormVisible: true,
  171. searchFormTemplate: 'searchformtpl',
  172. });
  173. // 为表格绑定事件
  174. Table.api.bindevent(table);
  175. // 离线安装
  176. require(['upload'], function (Upload) {
  177. Upload.api.upload("#faupload-addon", function (data, ret) {
  178. Config['addons'][data.addon.name] = data.addon;
  179. var addon = data.addon;
  180. var testdata = data.addon.testdata;
  181. operate(data.addon.name, 'enable', false, function (data, ret) {
  182. Layer.alert(__('Offline installed tips') + (testdata ? __('Testdata tips') : ""), {
  183. btn: testdata ? [__('Import testdata'), __('Skip testdata')] : [__('OK')],
  184. title: __('Warning'),
  185. yes: function (index) {
  186. if (testdata) {
  187. Fast.api.ajax({
  188. url: 'addon/testdata',
  189. data: {
  190. name: addon.name,
  191. version: addon.version,
  192. faversion: Config.faversion
  193. }
  194. }, function (data, ret) {
  195. Layer.close(index);
  196. });
  197. } else {
  198. Layer.close(index);
  199. }
  200. },
  201. icon: 1
  202. });
  203. });
  204. return false;
  205. }, function (data, ret) {
  206. if (ret.msg && ret.msg.match(/(login|登录)/g)) {
  207. return Layer.alert(ret.msg, {
  208. title: __('Warning'),
  209. btn: [__('Login now')],
  210. yes: function (index, layero) {
  211. $(".btn-userinfo").trigger("click");
  212. }
  213. });
  214. }
  215. });
  216. // 检测是否登录
  217. $(document).on("mousedown", "#faupload-addon", function (e) {
  218. var userinfo = Controller.api.userinfo.get();
  219. var uid = userinfo ? userinfo.id : 0;
  220. if (parseInt(uid) === 0) {
  221. $(".btn-userinfo").trigger("click");
  222. return false;
  223. }
  224. });
  225. });
  226. // 查看插件首页
  227. $(document).on("click", ".btn-addonindex", function () {
  228. if ($(this).attr("href") == 'javascript:;') {
  229. Layer.msg(__('Not installed tips'), {icon: 7});
  230. } else if ($(this).closest(".operate").find("a.btn-enable").length > 0) {
  231. Layer.msg(__('Not enabled tips'), {icon: 7});
  232. return false;
  233. }
  234. });
  235. // 切换
  236. $(document).on("click", ".btn-switch", function () {
  237. $(".btn-switch").removeClass("active");
  238. $(this).addClass("active");
  239. $("form.form-commonsearch input[name='type']").val($(this).data("type"));
  240. var method = $(this).data("type") == 'local' ? 'hideColumn' : 'showColumn';
  241. table.bootstrapTable(method, 'price');
  242. table.bootstrapTable(method, 'downloads');
  243. table.bootstrapTable('refresh', {url: ($(this).data("url") ? $(this).data("url") : $.fn.bootstrapTable.defaults.extend.index_url), pageNumber: 1});
  244. return false;
  245. });
  246. // 切换分类
  247. $(document).on("click", ".nav-category li a", function () {
  248. $(".nav-category li").removeClass("active");
  249. $(this).parent().addClass("active");
  250. $("form.form-commonsearch input[name='category_id']").val($(this).data("id"));
  251. table.bootstrapTable('refresh', {url: $(this).data("url"), pageNumber: 1});
  252. return false;
  253. });
  254. var tables = [];
  255. $(document).on("click", "#droptables", function () {
  256. if ($(this).prop("checked")) {
  257. Fast.api.ajax({
  258. url: "addon/get_table_list",
  259. async: false,
  260. data: {name: $(this).data("name")}
  261. }, function (data) {
  262. tables = data.tables;
  263. return false;
  264. });
  265. var html;
  266. html = tables.length > 0 ? '<div class="alert alert-warning-light droptablestips" style="max-width:480px;max-height:300px;overflow-y: auto;">' + __('The following data tables will be deleted') + ':<br>' + tables.join("<br>") + '</div>'
  267. : '<div class="alert alert-warning-light droptablestips">' + __('The Addon did not create a data table') + '</div>';
  268. $(html).insertAfter($(this).closest("p"));
  269. } else {
  270. $(".droptablestips").remove();
  271. }
  272. $(window).resize();
  273. });
  274. // 会员信息
  275. $(document).on("click", ".btn-userinfo", function (e, name, version) {
  276. var that = this;
  277. var area = [$(window).width() > 800 ? '500px' : '95%', $(window).height() > 600 ? '400px' : '95%'];
  278. var userinfo = Controller.api.userinfo.get();
  279. if (!userinfo) {
  280. Layer.open({
  281. content: Template("logintpl", {}),
  282. zIndex: 99,
  283. area: area,
  284. title: __('Login FastAdmin'),
  285. resize: false,
  286. btn: [__('Login'), __('Register')],
  287. yes: function (index, layero) {
  288. Fast.api.ajax({
  289. url: Config.api_url + '/user/login',
  290. type: 'post',
  291. data: {
  292. account: $("#inputAccount", layero).val(),
  293. password: $("#inputPassword", layero).val(),
  294. version: Config.faversion,
  295. }
  296. }, function (data, ret) {
  297. Controller.api.userinfo.set(data);
  298. Layer.closeAll();
  299. Layer.alert(ret.msg, {title: __('Warning'), icon: 1});
  300. return false;
  301. }, function (data, ret) {
  302. });
  303. },
  304. btn2: function () {
  305. return false;
  306. },
  307. success: function (layero, index) {
  308. this.checkEnterKey = function (event) {
  309. if (event.keyCode === 13) {
  310. $(".layui-layer-btn0").trigger("click");
  311. return false;
  312. }
  313. };
  314. $(document).on('keydown', this.checkEnterKey);
  315. $(".layui-layer-btn1", layero).prop("href", "https://www.fastadmin.net/user/register.html").prop("target", "_blank");
  316. },
  317. end: function () {
  318. $(document).off('keydown', this.checkEnterKey);
  319. }
  320. });
  321. } else {
  322. Fast.api.ajax({
  323. url: Config.api_url + '/user/index',
  324. data: {
  325. uid: userinfo.id,
  326. token: userinfo.token,
  327. version: Config.faversion,
  328. }
  329. }, function (data) {
  330. Layer.open({
  331. content: Template("userinfotpl", userinfo),
  332. area: area,
  333. title: __('Userinfo'),
  334. resize: false,
  335. btn: [__('Logout'), __('Close')],
  336. yes: function () {
  337. Fast.api.ajax({
  338. url: Config.api_url + '/user/logout',
  339. data: {uid: userinfo.id, token: userinfo.token, version: Config.faversion}
  340. }, function (data, ret) {
  341. Controller.api.userinfo.set(null);
  342. Layer.closeAll();
  343. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  344. }, function (data, ret) {
  345. Controller.api.userinfo.set(null);
  346. Layer.closeAll();
  347. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  348. });
  349. }
  350. });
  351. return false;
  352. }, function (data) {
  353. Controller.api.userinfo.set(null);
  354. $(that).trigger('click');
  355. return false;
  356. });
  357. }
  358. });
  359. //刷新授权
  360. $(document).on("click", ".btn-authorization", function () {
  361. var userinfo = Controller.api.userinfo.get();
  362. if (!userinfo) {
  363. $(".btn-userinfo").trigger("click");
  364. return false;
  365. }
  366. Layer.confirm(__('Are you sure you want to refresh authorization?'), {icon: 3, title: __('Warmtips')}, function () {
  367. Fast.api.ajax({
  368. url: 'addon/authorization',
  369. data: {
  370. uid: userinfo.id,
  371. token: userinfo.token
  372. }
  373. }, function (data, ret) {
  374. $(".btn-refresh").trigger("click");
  375. Layer.closeAll();
  376. });
  377. });
  378. return false;
  379. });
  380. var install = function (name, version, force) {
  381. var userinfo = Controller.api.userinfo.get();
  382. var uid = userinfo ? userinfo.id : 0;
  383. var token = userinfo ? userinfo.token : '';
  384. Fast.api.ajax({
  385. url: 'addon/install',
  386. data: {
  387. name: name,
  388. force: force ? 1 : 0,
  389. uid: uid,
  390. token: token,
  391. version: version,
  392. faversion: Config.faversion
  393. }
  394. }, function (data, ret) {
  395. Layer.closeAll();
  396. Config['addons'][data.addon.name] = ret.data.addon;
  397. operate(data.addon.name, 'enable', false, function () {
  398. Layer.alert(__('Online installed tips') + (data.addon.testdata ? __('Testdata tips') : ""), {
  399. btn: data.addon.testdata ? [__('Import testdata'), __('Skip testdata')] : [__('OK')],
  400. title: __('Warning'),
  401. yes: function (index) {
  402. if (data.addon.testdata) {
  403. Fast.api.ajax({
  404. url: 'addon/testdata',
  405. data: {
  406. name: name,
  407. uid: uid,
  408. token: token,
  409. version: version,
  410. faversion: Config.faversion
  411. }
  412. }, function (data, ret) {
  413. Layer.close(index);
  414. });
  415. } else {
  416. Layer.close(index);
  417. }
  418. },
  419. icon: 1
  420. });
  421. Controller.api.refresh(table, name);
  422. });
  423. }, function (data, ret) {
  424. var area = Fast.config.openArea != undefined ? Fast.config.openArea : [$(window).width() > 650 ? '650px' : '95%', $(window).height() > 710 ? '710px' : '95%'];
  425. if (ret && ret.code === -2) {
  426. //如果登录已经超时,重新提醒登录
  427. if (uid && uid != ret.data.uid) {
  428. Controller.api.userinfo.set(null);
  429. $(".operate[data-name='" + name + "'] .btn-install").trigger("click");
  430. return;
  431. }
  432. top.Fast.api.open(ret.data.payurl, __('Pay now'), {
  433. area: area,
  434. end: function () {
  435. Fast.api.ajax({
  436. url: 'addon/isbuy',
  437. data: {
  438. name: name,
  439. force: force ? 1 : 0,
  440. uid: uid,
  441. token: token,
  442. version: version,
  443. faversion: Config.faversion
  444. }
  445. }, function () {
  446. top.Layer.alert(__('Pay successful tips'), {
  447. btn: [__('Continue installation')],
  448. title: __('Warning'),
  449. icon: 1,
  450. yes: function (index) {
  451. top.Layer.close(index);
  452. install(name, version);
  453. }
  454. });
  455. return false;
  456. }, function () {
  457. console.log(__('Canceled'));
  458. return false;
  459. });
  460. }
  461. });
  462. } else if (ret && ret.code === -3) {
  463. //插件目录发现影响全局的文件
  464. Layer.open({
  465. content: Template("conflicttpl", ret.data),
  466. shade: 0.8,
  467. area: area,
  468. title: __('Warning'),
  469. btn: [__('Continue install'), __('Cancel')],
  470. end: function () {
  471. },
  472. yes: function () {
  473. install(name, version, true);
  474. }
  475. });
  476. } else {
  477. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  478. }
  479. return false;
  480. });
  481. };
  482. var uninstall = function (name, force, droptables) {
  483. Fast.api.ajax({
  484. url: 'addon/uninstall',
  485. data: {name: name, force: force ? 1 : 0, droptables: droptables ? 1 : 0}
  486. }, function (data, ret) {
  487. delete Config['addons'][name];
  488. Layer.closeAll();
  489. Controller.api.refresh(table, name);
  490. }, function (data, ret) {
  491. if (ret && ret.code === -3) {
  492. //插件目录发现影响全局的文件
  493. Layer.open({
  494. content: Template("conflicttpl", ret.data),
  495. shade: 0.8,
  496. area: area,
  497. title: __('Warning'),
  498. btn: [__('Continue uninstall'), __('Cancel')],
  499. end: function () {
  500. },
  501. yes: function () {
  502. uninstall(name, true, droptables);
  503. }
  504. });
  505. } else {
  506. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  507. }
  508. return false;
  509. });
  510. };
  511. var operate = function (name, action, force, success) {
  512. Fast.api.ajax({
  513. url: 'addon/state',
  514. data: {name: name, action: action, force: force ? 1 : 0}
  515. }, function (data, ret) {
  516. var addon = Config['addons'][name];
  517. addon.state = action === 'enable' ? 1 : 0;
  518. Layer.closeAll();
  519. if (typeof success === 'function') {
  520. success(data, ret);
  521. }
  522. Controller.api.refresh(table, name);
  523. }, function (data, ret) {
  524. if (ret && ret.code === -3) {
  525. //插件目录发现影响全局的文件
  526. Layer.open({
  527. content: Template("conflicttpl", ret.data),
  528. shade: 0.8,
  529. area: area,
  530. title: __('Warning'),
  531. btn: [__('Continue operate'), __('Cancel')],
  532. end: function () {
  533. },
  534. yes: function () {
  535. operate(name, action, true, success);
  536. }
  537. });
  538. } else {
  539. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  540. }
  541. return false;
  542. });
  543. };
  544. var upgrade = function (name, version) {
  545. var userinfo = Controller.api.userinfo.get();
  546. var uid = userinfo ? userinfo.id : 0;
  547. var token = userinfo ? userinfo.token : '';
  548. Fast.api.ajax({
  549. url: 'addon/upgrade',
  550. data: {name: name, uid: uid, token: token, version: version, faversion: Config.faversion}
  551. }, function (data, ret) {
  552. Config['addons'][name] = data.addon;
  553. Layer.closeAll();
  554. Controller.api.refresh(table, name);
  555. }, function (data, ret) {
  556. Layer.alert(ret.msg, {title: __('Warning')});
  557. return false;
  558. });
  559. };
  560. // 点击安装
  561. $(document).on("click", ".btn-install", function () {
  562. var that = this;
  563. var name = $(this).closest(".operate").data("name");
  564. var version = $(this).data("version");
  565. var userinfo = Controller.api.userinfo.get();
  566. var uid = userinfo ? userinfo.id : 0;
  567. if (parseInt(uid) === 0) {
  568. return Layer.alert(__('Not login tips'), {
  569. title: __('Warning'),
  570. btn: [__('Login now')],
  571. yes: function (index, layero) {
  572. $(".btn-userinfo").trigger("click", name, version);
  573. },
  574. btn2: function () {
  575. install(name, version, false);
  576. }
  577. });
  578. }
  579. install(name, version, false);
  580. });
  581. // 点击卸载
  582. $(document).on("click", ".btn-uninstall", function () {
  583. var name = $(this).closest(".operate").data('name');
  584. if (Config['addons'][name].state == 1) {
  585. Layer.alert(__('Please disable the add before trying to uninstall'), {icon: 7});
  586. return false;
  587. }
  588. Template.helper("__", __);
  589. Layer.confirm(Template("uninstalltpl", {addon: Config['addons'][name]}), {focusBtn: false}, function (index, layero) {
  590. uninstall(name, false, $("input[name='droptables']", layero).prop("checked"));
  591. });
  592. });
  593. // 点击配置
  594. $(document).on("click", ".btn-config", function () {
  595. var name = $(this).closest(".operate").data("name");
  596. Fast.api.open("addon/config?name=" + name, __('Setting'));
  597. });
  598. // 点击启用/禁用
  599. $(document).on("click", ".btn-enable,.btn-disable", function () {
  600. var name = $(this).data("name");
  601. var action = $(this).data("action");
  602. operate(name, action, false);
  603. });
  604. // 点击升级
  605. $(document).on("click", ".btn-upgrade", function () {
  606. var name = $(this).closest(".operate").data('name');
  607. if (Config['addons'][name].state == 1) {
  608. Layer.alert(__('Please disable the add before trying to upgrade'), {icon: 7});
  609. return false;
  610. }
  611. var version = $(this).data("version");
  612. Layer.confirm(__('Upgrade tips', Config['addons'][name].title), function (index, layero) {
  613. upgrade(name, version);
  614. });
  615. });
  616. $(document).on("click", ".operate .btn-group .dropdown-toggle", function () {
  617. $(this).closest(".btn-group").toggleClass("dropup", $(document).height() - $(this).offset().top <= 200);
  618. });
  619. $(document).on("click", ".view-screenshots", function () {
  620. var row = Table.api.getrowbyindex(table, parseInt($(this).data("index")));
  621. var data = [];
  622. $.each(row.screenshots, function (i, j) {
  623. data.push({
  624. "src": j
  625. });
  626. });
  627. var json = {
  628. "title": row.title,
  629. "data": data
  630. };
  631. top.Layer.photos(top.JSON.parse(JSON.stringify({photos: json})));
  632. });
  633. },
  634. add: function () {
  635. Controller.api.bindevent();
  636. },
  637. config: function () {
  638. $(document).on("click", ".nav-group li a[data-toggle='tab']", function () {
  639. if ($(this).attr("href") == "#all") {
  640. $(".tab-pane").addClass("active in");
  641. }
  642. return;
  643. var type = $(this).attr("href").substring(1);
  644. if (type == 'all') {
  645. $(".table-config tr").show();
  646. } else {
  647. $(".table-config tr").hide();
  648. $(".table-config tr[data-group='" + type + "']").show();
  649. }
  650. });
  651. Controller.api.bindevent();
  652. },
  653. api: {
  654. formatter: {
  655. title: function (value, row, index) {
  656. if ($(".btn-switch.active").data("type") == "local") {
  657. // return value;
  658. }
  659. var title = '<a class="title" href="' + row.url + '" data-toggle="tooltip" title="' + __('View addon home page') + '" target="_blank">' + value + '</a>';
  660. if (row.screenshots && row.screenshots.length > 0) {
  661. title += ' <a href="javascript:;" data-index="' + index + '" class="view-screenshots text-success" title="' + __('View addon screenshots') + '" data-toggle="tooltip"><i class="fa fa-image"></i></a>';
  662. }
  663. return title;
  664. },
  665. operate: function (value, row, index) {
  666. return Template("operatetpl", {item: row, index: index});
  667. },
  668. toggle: function (value, row, index) {
  669. if (!row.addon) {
  670. return '';
  671. }
  672. return '<a href="javascript:;" data-toggle="tooltip" title="' + __('Click to toggle status') + '" class="btn btn-toggle btn-' + (row.addon.state == 1 ? "disable" : "enable") + '" data-action="' + (row.addon.state == 1 ? "disable" : "enable") + '" data-name="' + row.name + '"><i class="fa ' + (row.addon.state == 0 ? 'fa-toggle-on fa-rotate-180 text-gray' : 'fa-toggle-on text-success') + ' fa-2x"></i></a>';
  673. },
  674. author: function (value, row, index) {
  675. var url = 'javascript:';
  676. if (typeof row.homepage !== 'undefined') {
  677. url = row.homepage;
  678. } else if (typeof row.qq !== 'undefined' && row.qq) {
  679. url = 'https://wpa.qq.com/msgrd?v=3&uin=' + row.qq + '&site=fastadmin.net&menu=yes';
  680. }
  681. return '<a href="' + url + '" target="_blank" data-toggle="tooltip" class="text-primary">' + value + '</a>';
  682. },
  683. price: function (value, row, index) {
  684. if (isNaN(value)) {
  685. return value;
  686. }
  687. return parseFloat(value) == 0 ? '<span class="text-success">' + __('Free') + '</span>' : '<span class="text-danger">¥' + value + '</span>';
  688. },
  689. downloads: function (value, row, index) {
  690. return value;
  691. },
  692. version: function (value, row, index) {
  693. return row.addon && row.addon.version != row.version ? '<a href="' + row.url + '?version=' + row.version + '" target="_blank"><span class="releasetips text-primary" data-toggle="tooltip" title="' + __('New version tips', row.version) + '">' + row.addon.version + '<i></i></span></a>' : row.version;
  694. },
  695. home: function (value, row, index) {
  696. return row.addon && parseInt(row.addon.state) > 0 ? '<a href="' + row.addon.url + '" data-toggle="tooltip" title="' + __('View addon index page') + '" target="_blank"><i class="fa fa-home text-primary"></i></a>' : '<a href="javascript:;"><i class="fa fa-home text-gray"></i></a>';
  697. },
  698. },
  699. bindevent: function () {
  700. Form.api.bindevent($("form[role=form]"));
  701. },
  702. userinfo: {
  703. get: function () {
  704. var userinfo = localStorage.getItem("fastadmin_userinfo");
  705. return userinfo ? JSON.parse(userinfo) : null;
  706. },
  707. set: function (data) {
  708. if (data) {
  709. localStorage.setItem("fastadmin_userinfo", JSON.stringify(data));
  710. } else {
  711. localStorage.removeItem("fastadmin_userinfo");
  712. }
  713. }
  714. },
  715. refresh: function (table, name) {
  716. //刷新左侧边栏
  717. Fast.api.refreshmenu();
  718. //刷新插件JS缓存
  719. Fast.api.ajax({url: require.toUrl('addons.js'), loading: false}, function () {
  720. return false;
  721. }, function () {
  722. return false;
  723. });
  724. //刷新行数据
  725. if ($(".operate[data-name='" + name + "']").length > 0) {
  726. var tr = $(".operate[data-name='" + name + "']").closest("tr[data-index]");
  727. var index = tr.data("index");
  728. var row = Table.api.getrowbyindex(table, index);
  729. row.addon = typeof Config['addons'][name] !== 'undefined' ? Config['addons'][name] : undefined;
  730. table.bootstrapTable("updateRow", {index: index, row: row});
  731. } else if ($(".btn-switch.active").data("type") == "local") {
  732. $(".btn-refresh").trigger("click");
  733. }
  734. }
  735. }
  736. };
  737. return Controller;
  738. });