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.
 
 
 
 
 
 

274 lines
7.9 KiB

  1. // Copyright 2013 Web Notes Technologies Pvt Ltd
  2. // License: MIT. See license.txt
  3. // wn._("Form")
  4. wn.ui.AppFrame = Class.extend({
  5. init: function(parent, title, module) {
  6. this.set_document_title = true;
  7. this.buttons = {};
  8. this.$w = $('<div class="col-span-12"></div>').prependTo(parent);
  9. $('<!-- div>\
  10. <ul class="breadcrumb" style="height: 32px;">\
  11. <span class="appframe-right pull-right">\
  12. <span class="btn-group"></span>\
  13. </span>\
  14. </ul>\
  15. </div>\
  16. <div class="toolbar-area"></div -->\
  17. <div class="title-button-area btn-group pull-right" style="margin-top: 10px;"></div>\
  18. <div class="title-area"><h3 style="display: inline-block">\
  19. <span class="title-icon"></span><span class="title-text"></span></h3></div>\
  20. <div class="sub-title-area text-muted small" \
  21. style="margin-top: -10px;"></div>\
  22. <div class="btn-group appframe-toolbar" \
  23. style="display: none; margin-top: 15px;"></div>\
  24. <hr>\
  25. ').appendTo(this.$w);
  26. this.$w.find('.close').click(function() {
  27. window.history.back();
  28. })
  29. this.toolbar = this.$w.find(".appframe-toolbar");
  30. if(title)
  31. this.set_title(title);
  32. },
  33. get_title_area: function() {
  34. return this.$w.find(".title-area");
  35. },
  36. set_title: function(txt, full_text) {
  37. this.title = txt;
  38. this.$w.find(".breadcrumb .appframe-title").html(txt);
  39. this.$w.find(".title-text").html(txt);
  40. },
  41. set_sub_title: function(txt) {
  42. this.$w.find(".sub-title-area").html(txt);
  43. },
  44. clear_breadcrumbs: function() {
  45. this.$w.find(".breadcrumb").empty();
  46. },
  47. add_breadcrumb: function(icon, link, title) {
  48. if(link) {
  49. $(repl('<li style="margin-top: 5px;"><a href="#%(link)s" title="%(title)s"><i class="%(icon)s"></i></a>\
  50. <span class="divider">/</span></li>', {
  51. icon: icon,
  52. link: link,
  53. title: wn._(title)
  54. })).appendTo(this.$w.find(".breadcrumb"));
  55. } else {
  56. $(repl("<li style='margin-top: 5px;' class='active'><i class='%(icon)s'></i> \
  57. <span class='appframe-title'></span>\
  58. <span class='appframe-subject'></span></li>", {
  59. icon: icon,
  60. })).appendTo(this.$w.find(".breadcrumb"));
  61. if(this.title) this.set_title(this.title);
  62. }
  63. },
  64. add_home_breadcrumb: function() {
  65. this.add_breadcrumb("icon-home", wn.home_page, "Home");
  66. },
  67. add_list_breadcrumb: function(doctype) {
  68. this.add_breadcrumb("icon-list", "List/" + encodeURIComponent(doctype), doctype + " List");
  69. },
  70. add_module_icon: function(module) {
  71. var module_info = wn.modules[module];
  72. if(module_info) {
  73. this.$w.find(".title-icon").html('<i class="'
  74. +module_info.icon+'"></i> ')
  75. .css({"cursor":"pointer"})
  76. .attr("module-name", module)
  77. .click(function() {
  78. wn.set_route(wn.modules[$(this).attr("module-name")].link);
  79. });
  80. this.$w.prepend("<div>").css({
  81. "border-top": "7px solid " + module_info.color
  82. });
  83. // this.$w.find(".title-area").css({
  84. // "border-left": "5px solid " + module_info.color
  85. // })
  86. }
  87. },
  88. set_views_for: function(doctype, active_view) {
  89. this.doctype = doctype;
  90. var me = this;
  91. var views = [{
  92. icon: "icon-file-alt",
  93. route: "",
  94. type: "form",
  95. set_route: function() {
  96. if(wn.views.formview[me.doctype]) {
  97. wn.set_route("Form", me.doctype, wn.views.formview[me.doctype].frm.docname);
  98. } else {
  99. new_doc(doctype);
  100. }
  101. }
  102. }];
  103. if(!locals.DocType[doctype].issingle) {
  104. views.push({
  105. icon: "icon-list",
  106. route: "List/" + doctype,
  107. type: "list"
  108. });
  109. }
  110. if(locals.DocType[doctype].__calendar_js) {
  111. views.push({
  112. icon: "icon-calendar",
  113. route: "Calendar/" + doctype,
  114. type: "calendar"
  115. });
  116. }
  117. if(wn.model.can_get_report(doctype)) {
  118. views.push({
  119. icon: "icon-table",
  120. route: "Report2/" + doctype,
  121. type: "report"
  122. });
  123. }
  124. this.set_views(views, active_view);
  125. },
  126. set_views: function(views, active_view) {
  127. var me = this;
  128. $right = this.$w.find(".appframe-right .btn-group");
  129. $.each(views, function(i, e) {
  130. var btn = $(repl('<button class="btn" data-route="%(route)s">\
  131. <i class="%(icon)s"></i></button>', e))
  132. .click(e.set_route || function() {
  133. window.location.hash = "#" + $(this).attr("data-route");
  134. })
  135. .css({
  136. width: "39px"
  137. })
  138. .attr("title", wn._(toTitle(e.type)))
  139. .appendTo($right);
  140. if(e.type==active_view) {
  141. btn.addClass("btn-inverse");
  142. }
  143. });
  144. },
  145. add_help_button: function(txt) {
  146. $('<button class="btn" button-type="help">\
  147. <b>?</b></button>')
  148. .data('help-text', txt)
  149. .click(function() { msgprint($(this).data('help-text'), 'Help'); })
  150. .appendTo(this.toolbar);
  151. },
  152. clear_buttons: function() {
  153. this.toolbar && this.toolbar.empty().toggle(false);
  154. $(".custom-menu").remove();
  155. },
  156. add_button: function(label, click, icon, title_toolbar) {
  157. !title_toolbar && this.toolbar.toggle(true);
  158. args = { label: label, icon:'' };
  159. if(icon) {
  160. args.icon = '<i class="'+icon+'"></i>';
  161. }
  162. this.buttons[label] = $(repl('<button class="btn">\
  163. %(icon)s %(label)s</button>', args))
  164. .appendTo(title_toolbar ? this.$w.find(".title-button-area") : this.toolbar)
  165. .click(click);
  166. return this.buttons[label];
  167. },
  168. get_menu: function(label) {
  169. return $("#navbar-" + label.toLowerCase());
  170. },
  171. add_menu_divider: function(menu) {
  172. menu = typeof menu == "string" ?
  173. this.get_menu(menu) : menu;
  174. $('<li class="divider custom-menu"></li>').appendTo(menu);
  175. },
  176. add_dropdown_button: function(parent, label, click, icon) {
  177. var menu = this.get_menu(parent);
  178. if(menu.find("li:not(.custom-menu)").length && !menu.find(".divider").length) {
  179. this.add_menu_divider(menu);
  180. }
  181. return $('<li class="custom-menu"><a><i class="'
  182. +icon+'"></i> '+label+'</a></li>')
  183. .appendTo(menu)
  184. .find("a")
  185. .click(function() {
  186. click();
  187. });
  188. },
  189. add_label: function(label) {
  190. return $("<span class='label'>"+label+" </span>")
  191. .appendTo($("<li>").appendTo(this.toolbar));
  192. },
  193. add_select: function(label, options) {
  194. this.add_toolbar();
  195. return $("<select class='col-span-2' style='margin-top: 5px;'>")
  196. .add_options(options)
  197. .appendTo($("<li>").appendTo(this.toolbar));
  198. },
  199. add_data: function(label) {
  200. this.add_toolbar();
  201. return $("<input class='col-span-2' style='margin-top: 5px;' type='text' placeholder='"+ label +"'>")
  202. .appendTo($("<li>").appendTo(this.toolbar));
  203. },
  204. add_date: function(label, date) {
  205. this.add_toolbar();
  206. return $("<input class='col-span-2' style='margin-top: 5px;' type='text'>").datepicker({
  207. dateFormat: sys_defaults.date_format.replace("yyyy", "yy"),
  208. changeYear: true,
  209. }).val(dateutil.str_to_user(date) || "")
  210. .appendTo($("<li>").appendTo(this.toolbar));
  211. },
  212. add_check: function(label) {
  213. this.add_toolbar();
  214. return $("<label style='display: inline;'><input type='checkbox' \
  215. style='margin-top: 5px;'/> " + label + "</label>")
  216. .appendTo($("<li>").appendTo(this.toolbar))
  217. .find("input");
  218. },
  219. add_ripped_paper_effect: function(wrapper) {
  220. if(!wrapper) var wrapper = wn.container.page;
  221. var layout_main = $(wrapper).find('.layout-main');
  222. if(!layout_main.length) {
  223. layout_main = $(wrapper).find('.layout-main-section');
  224. }
  225. layout_main.css({"padding-top":"25px"});
  226. $('<div class="ripped-paper-border"></div>')
  227. .prependTo(layout_main)
  228. .css({"width": $(layout_main).width()});
  229. }
  230. });
  231. // parent, title, single_column
  232. // standard page with appframe
  233. wn.ui.make_app_page = function(opts) {
  234. if(opts.single_column) {
  235. $('<div class="appframe col-span-12">\
  236. <div class="layout-appframe row"></div>\
  237. <div class="layout-main"></div>\
  238. </div>').appendTo(opts.parent);
  239. } else {
  240. $('<div class="appframe col-span-12">\
  241. <div class="layout-appframe row"></div>\
  242. <div class="row">\
  243. <div class="layout-main-section col-span-9"></div>\
  244. <div class="layout-side-section col-span-3"></div>\
  245. </div>\
  246. </div>').appendTo(opts.parent);
  247. }
  248. opts.parent.appframe = new wn.ui.AppFrame($(opts.parent).find('.layout-appframe'));
  249. if(opts.set_document_title!==undefined)
  250. opts.parent.appframe.set_document_title = opts.set_document_title;
  251. if(opts.title) opts.parent.appframe.set_title(opts.title);
  252. }