addon.js 36 KB

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