You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

103 lines
2.4 KiB

  1. frappe.provide("frappe.applications");
  2. frappe.pages['applications'].onload = function(parent) {
  3. frappe.applications.installer = new frappe.applications.Installer(parent);
  4. };
  5. frappe.applications.Installer = Class.extend({
  6. init: function(parent) {
  7. this.parent = parent;
  8. this.get_app_list();
  9. },
  10. get_app_list: function() {
  11. var me = this;
  12. return frappe.call({
  13. method: "frappe.desk.page.applications.applications.get_app_list",
  14. callback: function(r) {
  15. var apps = r.message;
  16. me.make_page();
  17. // no apps
  18. if(!keys(apps).length) {
  19. me.wrapper.html('<div class="text-muted app-listing padding">' + __("No Apps Installed") + '</div>');
  20. return;
  21. }
  22. me.wrapper.empty();
  23. me.make_search();
  24. me.make_app_list(apps);
  25. }
  26. });
  27. },
  28. make_search: function() {
  29. var me = this;
  30. $('<div class="padding search-wrapper"><div class="form-group">\
  31. <input type="text" class="form-control app-search" placeholder="Search" name="search"/></div></div>')
  32. .appendTo(this.wrapper)
  33. .find(".app-search")
  34. .on("keyup", function() {
  35. var val = ($(this).val() || "").toLowerCase();
  36. me.wrapper.find(".app-listing").each(function() {
  37. $(this).toggle($(this).attr("data-title").toLowerCase().indexOf(val)!==-1);
  38. });
  39. });
  40. },
  41. make_app_list: function(apps) {
  42. var me = this;
  43. $.each(Object.keys(apps).sort(), function(i, app_key) {
  44. var app = apps[app_key];
  45. frappe.modules[app_key] = {
  46. label: app.app_title,
  47. icon: app.app_icon,
  48. color: app.app_color,
  49. is_app: true
  50. };
  51. app.app_icon = frappe.ui.app_icon.get_html(app_key);
  52. $(frappe.render_template("application_row", {app: app})).appendTo(me.wrapper);
  53. });
  54. this.wrapper.find(".install").on("click", function() {
  55. me.install_app($(this).attr("data-app"));
  56. });
  57. },
  58. install_app: function(app_name) {
  59. frappe.call({
  60. method: "frappe.desk.page.applications.applications.install_app",
  61. args: { name: app_name },
  62. callback: function(r) {
  63. if(!r.exc) {
  64. msgprint("<i class='icon-ok'></i>" + __("Installed"));
  65. msgprint(__("Refreshing..."));
  66. setTimeout(function() { window.location.reload() }, 2000)
  67. }
  68. }
  69. });
  70. },
  71. make_page: function() {
  72. if (this.page)
  73. return;
  74. frappe.ui.make_app_page({
  75. parent: this.parent,
  76. title: __('Application Installer'),
  77. icon: "icon-download",
  78. single_column: true
  79. });
  80. this.page = this.parent.page;
  81. this.wrapper = $('<div></div>').appendTo(this.page.main);
  82. }
  83. });