addon.js 38 KB

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