addon.js 39 KB

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