addon.js 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763
  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: Config.api_url + '/user/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: 1});
  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", "https://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: Config.api_url + '/user/index',
  327. data: {
  328. uid: userinfo.id,
  329. token: userinfo.token,
  330. version: Config.faversion,
  331. }
  332. }, function (data) {
  333. Layer.open({
  334. content: Template("userinfotpl", userinfo),
  335. area: area,
  336. title: __('Userinfo'),
  337. resize: false,
  338. btn: [__('Logout'), __('Cancel')],
  339. yes: function () {
  340. Fast.api.ajax({
  341. url: Config.api_url + '/user/logout',
  342. data: {uid: userinfo.id, token: userinfo.token, version: Config.faversion}
  343. }, function (data, ret) {
  344. Controller.api.userinfo.set(null);
  345. Layer.closeAll();
  346. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  347. }, function (data, ret) {
  348. Controller.api.userinfo.set(null);
  349. Layer.closeAll();
  350. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  351. });
  352. }
  353. });
  354. return false;
  355. }, function (data) {
  356. Controller.api.userinfo.set(null);
  357. $(that).trigger('click');
  358. return false;
  359. });
  360. }
  361. });
  362. //刷新授权
  363. $(document).on("click", ".btn-authorization", function () {
  364. var userinfo = Controller.api.userinfo.get();
  365. if (!userinfo) {
  366. $(".btn-userinfo").trigger("click");
  367. return false;
  368. }
  369. Layer.confirm(__('Are you sure you want to refresh authorization?'), {icon: 3, title: __('Warmtips')}, function () {
  370. Fast.api.ajax({
  371. url: 'addon/authorization',
  372. data: {
  373. uid: userinfo.id,
  374. token: userinfo.token
  375. }
  376. }, function (data, ret) {
  377. $(".btn-refresh").trigger("click");
  378. Layer.closeAll();
  379. });
  380. });
  381. return false;
  382. });
  383. var install = function (name, version, force) {
  384. var userinfo = Controller.api.userinfo.get();
  385. var uid = userinfo ? userinfo.id : 0;
  386. var token = userinfo ? userinfo.token : '';
  387. Fast.api.ajax({
  388. url: 'addon/install',
  389. data: {
  390. name: name,
  391. force: force ? 1 : 0,
  392. uid: uid,
  393. token: token,
  394. version: version,
  395. faversion: Config.faversion
  396. }
  397. }, function (data, ret) {
  398. Layer.closeAll();
  399. Config['addons'][data.addon.name] = ret.data.addon;
  400. operate(data.addon.name, 'enable', false, function () {
  401. Layer.alert(__('Online installed tips') + (data.addon.testdata ? __('Testdata tips') : ""), {
  402. btn: data.addon.testdata ? [__('Import testdata'), __('Skip testdata')] : [__('OK')],
  403. title: __('Warning'),
  404. yes: function (index) {
  405. if (data.addon.testdata) {
  406. Fast.api.ajax({
  407. url: 'addon/testdata',
  408. data: {
  409. name: name,
  410. uid: uid,
  411. token: token,
  412. version: version,
  413. faversion: Config.faversion
  414. }
  415. }, function (data, ret) {
  416. Layer.close(index);
  417. });
  418. } else {
  419. Layer.close(index);
  420. }
  421. },
  422. icon: 1
  423. });
  424. Controller.api.refresh(table, name);
  425. });
  426. }, function (data, ret) {
  427. var area = Fast.config.openArea != undefined ? Fast.config.openArea : [$(window).width() > 650 ? '650px' : '95%', $(window).height() > 710 ? '710px' : '95%'];
  428. if (ret && ret.code === -2) {
  429. //如果登录已经超时,重新提醒登录
  430. if (uid && uid != ret.data.uid) {
  431. Controller.api.userinfo.set(null);
  432. $(".operate[data-name='" + name + "'] .btn-install").trigger("click");
  433. return;
  434. }
  435. top.Fast.api.open(ret.data.payurl, __('Pay now'), {
  436. area: area,
  437. end: function () {
  438. Fast.api.ajax({
  439. url: 'addon/isbuy',
  440. data: {
  441. name: name,
  442. force: force ? 1 : 0,
  443. uid: uid,
  444. token: token,
  445. version: version,
  446. faversion: Config.faversion
  447. }
  448. }, function () {
  449. top.Layer.alert(__('Pay successful tips'), {
  450. btn: [__('Continue installation')],
  451. title: __('Warning'),
  452. icon: 1,
  453. yes: function (index) {
  454. top.Layer.close(index);
  455. install(name, version);
  456. }
  457. });
  458. return false;
  459. }, function () {
  460. console.log(__('Canceled'));
  461. return false;
  462. });
  463. }
  464. });
  465. } else if (ret && ret.code === -3) {
  466. //插件目录发现影响全局的文件
  467. Layer.open({
  468. content: Template("conflicttpl", ret.data),
  469. shade: 0.8,
  470. area: area,
  471. title: __('Warning'),
  472. btn: [__('Continue install'), __('Cancel')],
  473. end: function () {
  474. },
  475. yes: function () {
  476. install(name, version, true);
  477. }
  478. });
  479. } else {
  480. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  481. }
  482. return false;
  483. });
  484. };
  485. var uninstall = function (name, force, droptables) {
  486. Fast.api.ajax({
  487. url: 'addon/uninstall',
  488. data: {name: name, force: force ? 1 : 0, droptables: droptables ? 1 : 0}
  489. }, function (data, ret) {
  490. delete Config['addons'][name];
  491. Layer.closeAll();
  492. Controller.api.refresh(table, name);
  493. }, function (data, ret) {
  494. if (ret && ret.code === -3) {
  495. //插件目录发现影响全局的文件
  496. Layer.open({
  497. content: Template("conflicttpl", ret.data),
  498. shade: 0.8,
  499. area: area,
  500. title: __('Warning'),
  501. btn: [__('Continue uninstall'), __('Cancel')],
  502. end: function () {
  503. },
  504. yes: function () {
  505. uninstall(name, true, droptables);
  506. }
  507. });
  508. } else {
  509. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  510. }
  511. return false;
  512. });
  513. };
  514. var operate = function (name, action, force, success) {
  515. Fast.api.ajax({
  516. url: 'addon/state',
  517. data: {name: name, action: action, force: force ? 1 : 0}
  518. }, function (data, ret) {
  519. var addon = Config['addons'][name];
  520. addon.state = action === 'enable' ? 1 : 0;
  521. Layer.closeAll();
  522. if (typeof success === 'function') {
  523. success(data, ret);
  524. }
  525. Controller.api.refresh(table, name);
  526. }, function (data, ret) {
  527. if (ret && ret.code === -3) {
  528. //插件目录发现影响全局的文件
  529. Layer.open({
  530. content: Template("conflicttpl", ret.data),
  531. shade: 0.8,
  532. area: area,
  533. title: __('Warning'),
  534. btn: [__('Continue operate'), __('Cancel')],
  535. end: function () {
  536. },
  537. yes: function () {
  538. operate(name, action, true, success);
  539. }
  540. });
  541. } else {
  542. Layer.alert(ret.msg, {title: __('Warning'), icon: 0});
  543. }
  544. return false;
  545. });
  546. };
  547. var upgrade = function (name, version) {
  548. var userinfo = Controller.api.userinfo.get();
  549. var uid = userinfo ? userinfo.id : 0;
  550. var token = userinfo ? userinfo.token : '';
  551. Fast.api.ajax({
  552. url: 'addon/upgrade',
  553. data: {name: name, uid: uid, token: token, version: version, faversion: Config.faversion}
  554. }, function (data, ret) {
  555. Config['addons'][name] = data.addon;
  556. Layer.closeAll();
  557. Controller.api.refresh(table, name);
  558. }, function (data, ret) {
  559. Layer.alert(ret.msg, {title: __('Warning')});
  560. return false;
  561. });
  562. };
  563. // 点击安装
  564. $(document).on("click", ".btn-install", function () {
  565. var that = this;
  566. var name = $(this).closest(".operate").data("name");
  567. var version = $(this).data("version");
  568. var userinfo = Controller.api.userinfo.get();
  569. var uid = userinfo ? userinfo.id : 0;
  570. if (parseInt(uid) === 0) {
  571. return Layer.alert(__('Not login tips'), {
  572. title: __('Warning'),
  573. btn: [__('Login now')],
  574. yes: function (index, layero) {
  575. $(".btn-userinfo").trigger("click", name, version);
  576. },
  577. btn2: function () {
  578. install(name, version, false);
  579. }
  580. });
  581. }
  582. install(name, version, false);
  583. });
  584. // 点击卸载
  585. $(document).on("click", ".btn-uninstall", function () {
  586. var name = $(this).closest(".operate").data('name');
  587. if (Config['addons'][name].state == 1) {
  588. Layer.alert(__('Please disable the add before trying to uninstall'), {icon: 7});
  589. return false;
  590. }
  591. Template.helper("__", __);
  592. Layer.confirm(Template("uninstalltpl", {addon: Config['addons'][name]}), {focusBtn: false}, function (index, layero) {
  593. uninstall(name, false, $("input[name='droptables']", layero).prop("checked"));
  594. });
  595. });
  596. // 点击配置
  597. $(document).on("click", ".btn-config", function () {
  598. var name = $(this).closest(".operate").data("name");
  599. Fast.api.open("addon/config?name=" + name, __('Setting'));
  600. });
  601. // 点击启用/禁用
  602. $(document).on("click", ".btn-enable,.btn-disable", function () {
  603. var name = $(this).data("name");
  604. var action = $(this).data("action");
  605. operate(name, action, false);
  606. });
  607. // 点击升级
  608. $(document).on("click", ".btn-upgrade", function () {
  609. var name = $(this).closest(".operate").data('name');
  610. if (Config['addons'][name].state == 1) {
  611. Layer.alert(__('Please disable the add before trying to upgrade'), {icon: 7});
  612. return false;
  613. }
  614. var version = $(this).data("version");
  615. Layer.confirm(__('Upgrade tips', Config['addons'][name].title), function (index, layero) {
  616. upgrade(name, version);
  617. });
  618. });
  619. $(document).on("click", ".operate .btn-group .dropdown-toggle", function () {
  620. $(this).closest(".btn-group").toggleClass("dropup", $(document).height() - $(this).offset().top <= 200);
  621. });
  622. $(document).on("click", ".view-screenshots", function () {
  623. var row = Table.api.getrowbyindex(table, parseInt($(this).data("index")));
  624. var data = [];
  625. $.each(row.screenshots, function (i, j) {
  626. data.push({
  627. "src": j
  628. });
  629. });
  630. var json = {
  631. "title": row.title,
  632. "data": data
  633. };
  634. top.Layer.photos(top.JSON.parse(JSON.stringify({photos: json})));
  635. });
  636. },
  637. add: function () {
  638. Controller.api.bindevent();
  639. },
  640. config: function () {
  641. Controller.api.bindevent();
  642. },
  643. api: {
  644. formatter: {
  645. title: function (value, row, index) {
  646. var title = '<a class="title" href="' + row.url + '" data-toggle="tooltip" title="' + __('View addon home page') + '" target="_blank">' + value + '</a>';
  647. if (row.screenshots && row.screenshots.length > 0) {
  648. 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>';
  649. }
  650. return title;
  651. },
  652. operate: function (value, row, index) {
  653. return Template("operatetpl", {item: row, index: index});
  654. },
  655. toggle: function (value, row, index) {
  656. if (!row.addon) {
  657. return '';
  658. }
  659. 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>';
  660. },
  661. author: function (value, row, index) {
  662. var url = 'javascript:';
  663. if (typeof row.homepage !== 'undefined') {
  664. url = row.homepage;
  665. } else if (typeof row.qq !== 'undefined' && row.qq) {
  666. url = 'https://wpa.qq.com/msgrd?v=3&uin=' + row.qq + '&site=fastadmin.net&menu=yes';
  667. }
  668. return '<a href="' + url + '" target="_blank" data-toggle="tooltip" class="text-primary">' + value + '</a>';
  669. },
  670. price: function (value, row, index) {
  671. if (isNaN(value)) {
  672. return value;
  673. }
  674. return parseFloat(value) == 0 ? '<span class="text-success">' + __('Free') + '</span>' : '<span class="text-danger">¥' + value + '</span>';
  675. },
  676. downloads: function (value, row, index) {
  677. return value;
  678. },
  679. version: function (value, row, index) {
  680. 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;
  681. },
  682. home: function (value, row, index) {
  683. 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>';
  684. },
  685. },
  686. bindevent: function () {
  687. Form.api.bindevent($("form[role=form]"));
  688. },
  689. userinfo: {
  690. get: function () {
  691. var userinfo = localStorage.getItem("fastadmin_userinfo");
  692. return userinfo ? JSON.parse(userinfo) : null;
  693. },
  694. set: function (data) {
  695. if (data) {
  696. localStorage.setItem("fastadmin_userinfo", JSON.stringify(data));
  697. } else {
  698. localStorage.removeItem("fastadmin_userinfo");
  699. }
  700. }
  701. },
  702. refresh: function (table, name) {
  703. //刷新左侧边栏
  704. Fast.api.refreshmenu();
  705. //刷新插件JS缓存
  706. Fast.api.ajax({url: require.toUrl('addons.js'), loading: false}, function () {
  707. return false;
  708. }, function () {
  709. return false;
  710. });
  711. //刷新行数据
  712. if ($(".operate[data-name='" + name + "']").length > 0) {
  713. var tr = $(".operate[data-name='" + name + "']").closest("tr[data-index]");
  714. var index = tr.data("index");
  715. var row = Table.api.getrowbyindex(table, index);
  716. row.addon = typeof Config['addons'][name] !== 'undefined' ? Config['addons'][name] : undefined;
  717. table.bootstrapTable("updateRow", {index: index, row: row});
  718. } else if ($(".btn-switch.active").data("type") == "local") {
  719. $(".btn-refresh").trigger("click");
  720. }
  721. }
  722. }
  723. };
  724. return Controller;
  725. });