addon.js 37 KB

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