addon.js 37 KB

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