addon.js 37 KB

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