addon.js 38 KB

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