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.
 
 
 
 
 
 

355 lines
9.8 KiB

  1. // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
  2. // MIT License. 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.fields_dict = {};
  9. this.$w = $('<div class="appframe-header col-md-12">\
  10. <div class="row appframe-title">\
  11. <div class="col-md-12">\
  12. <div class="title-button-area btn-group pull-right" \
  13. style="margin-top: 10px;"></div>\
  14. <div class="title-button-area-1 btn-group pull-right" \
  15. style="margin-top: 10px;"></div>\
  16. <div class="title-area"><h2 style="display: inline-block">\
  17. <span class="title-icon text-muted" style="display: none"></span>\
  18. <span class="title-text"></span></h2></div>\
  19. <div class="sub-title-area text-muted small">&nbsp;</div>\
  20. <div class="mini-bar"><ul></ul></div>\
  21. </div>\
  22. </div>\
  23. <div class="appframe-toolbar" style="display: none;"></div>\
  24. <div>').prependTo(parent);
  25. this.$w.find('.close').click(function() {
  26. window.history.back();
  27. })
  28. this.toolbar = this.$w.find(".appframe-toolbar");
  29. this.setup_toolbar();
  30. if(title)
  31. this.set_title(title);
  32. },
  33. setup_toolbar: function() {
  34. $('<div class="btn-group pull-left form-group"></div>\
  35. <div class="appframe-form"></div>\
  36. <div class="clearfix"></div>').appendTo(this.toolbar.toggle(false));
  37. },
  38. get_title_area: function() {
  39. return this.$w.find(".title-area");
  40. },
  41. set_title: function(txt, full_text) {
  42. // strip icon
  43. this.title = txt;
  44. document.title = txt.replace(/<[^>]*>/g, "");
  45. this.$w.find(".breadcrumb .appframe-title").html(txt);
  46. this.$w.find(".title-text").html(txt);
  47. },
  48. set_sub_title: function(txt) {
  49. this.$w.find(".sub-title-area").html(txt);
  50. },
  51. add_to_mini_bar: function(icon, label, click) {
  52. var $ul = this.$w.find(".mini-bar ul"),
  53. $li = $('<li><i class="'+icon+'"></i></li>')
  54. .attr("title", label)
  55. .appendTo($ul)
  56. .click(function() {
  57. click();
  58. return false;
  59. })
  60. return $li;
  61. },
  62. hide_mini_bar: function() {
  63. this.$w.find(".mini-bar").toggle(false);
  64. },
  65. show_mini_bar: function() {
  66. this.$w.find(".mini-bar").toggle(true);
  67. },
  68. add_module_icon: function(module, doctype, onclick) {
  69. var module_info = wn.modules[module];
  70. if(!module_info) {
  71. module_info = {
  72. icon: "icon-question-sign",
  73. color: "#ddd"
  74. }
  75. }
  76. var icon = wn.boot.doctype_icons[doctype] || module_info.icon;
  77. this.$w.find(".title-icon").html('<i class="'+icon+'"></i> ')
  78. .toggle(true)
  79. .attr("doctype-name", doctype)
  80. .attr("module-link", module_info.link)
  81. .click(onclick || function() {
  82. var route = wn.get_route();
  83. var doctype = $(this).attr("doctype-name");
  84. if(doctype && route[0]!=="List" && !locals["DocType"][doctype].issingle) {
  85. wn.set_route("List", doctype)
  86. } else if($(this).attr("module-link")!==route[0]){
  87. wn.set_route($(this).attr("module-link"));
  88. } else {
  89. wn.set_route("");
  90. }
  91. return false;
  92. });
  93. },
  94. set_views_for: function(doctype, active_view) {
  95. this.doctype = doctype;
  96. var me = this,
  97. meta = locals.DocType[doctype],
  98. views = [],
  99. module_info = wn.modules[meta.module];
  100. if(module_info) {
  101. views.push({
  102. icon: module_info.icon,
  103. route: module_info.link,
  104. type: "module"
  105. })
  106. }
  107. views.push({
  108. icon: "icon-file-alt",
  109. route: "",
  110. type: "form",
  111. set_route: function() {
  112. if(wn.views.formview[me.doctype]) {
  113. wn.set_route("Form", me.doctype, wn.views.formview[me.doctype].frm.docname);
  114. } else {
  115. new_doc(doctype);
  116. }
  117. }
  118. });
  119. if(!meta.issingle) {
  120. views.push({
  121. icon: "icon-list",
  122. route: "List/" + doctype,
  123. type: "list"
  124. });
  125. }
  126. if(wn.views.calendar[doctype]) {
  127. views.push({
  128. icon: "icon-calendar",
  129. route: "Calendar/" + doctype,
  130. type: "calendar"
  131. });
  132. }
  133. if(wn.views.calendar[doctype] && wn.views.calendar[doctype]) {
  134. views.push({
  135. icon: "icon-tasks",
  136. route: "Gantt/" + doctype,
  137. type: "gantt"
  138. });
  139. }
  140. if(wn.model.can_get_report(doctype)) {
  141. views.push({
  142. icon: "icon-table",
  143. route: "Report/" + doctype,
  144. type: "report"
  145. });
  146. }
  147. this.set_views(views, active_view);
  148. },
  149. set_views: function(views, active_view) {
  150. var me = this;
  151. $right = this.$w.find(".title-button-area");
  152. $.each(views, function(i, e) {
  153. var btn = $(repl('<button class="btn btn-default" data-route="%(route)s">\
  154. <i class="%(icon)s"></i></button>', e))
  155. .click(e.set_route || function() {
  156. window.location.hash = "#" + $(this).attr("data-route");
  157. })
  158. .css({
  159. width: "39px"
  160. })
  161. .attr("title", wn._(toTitle(e.type)))
  162. .appendTo($right);
  163. if(e.type===active_view) {
  164. btn.css({"color": "#428bca"});
  165. }
  166. });
  167. },
  168. add_help_button: function(txt) {
  169. $('<button class="btn btn-default pull-right" button-type="help">\
  170. <b>?</b></button>')
  171. .data('help-text', txt)
  172. .click(function() { msgprint($(this).data('help-text'), 'Help'); })
  173. .insertBefore(this.toolbar.find(".clearfix"));
  174. },
  175. show_toolbar: function() {
  176. this.toolbar.toggle(true);
  177. },
  178. clear_buttons: function() {
  179. this.toolbar.empty();
  180. this.setup_toolbar();
  181. $(".custom-menu").remove();
  182. },
  183. add_button: function(label, click, icon, is_title) {
  184. this.show_toolbar();
  185. args = { label: wn._(label), icon:'' };
  186. if(icon) {
  187. args.icon = '<i class="'+icon+'"></i>';
  188. }
  189. this.buttons[label] && this.buttons[label].remove();
  190. var append_or_prepend = is_title ? "prependTo" : "appendTo";
  191. this.buttons[label] = $(repl('<button class="btn btn-default">\
  192. %(icon)s <span class="hidden-xs-inline">%(label)s</span></button>', args))
  193. [append_or_prepend](this.toolbar.find(".btn-group").css({"margin-right": "5px"}))
  194. .attr("title", wn._(label))
  195. .click(click);
  196. if(is_title) {
  197. this.buttons[label].addClass("btn-title");
  198. }
  199. return this.buttons[label];
  200. },
  201. get_menu: function(label) {
  202. return $("#navbar-" + label.toLowerCase());
  203. },
  204. add_menu_divider: function(menu) {
  205. menu = typeof menu == "string" ?
  206. this.get_menu(menu) : menu;
  207. $('<li class="divider custom-menu"></li>').prependTo(menu);
  208. },
  209. add_dropdown_button: function(parent, label, click, icon) {
  210. var menu = this.get_menu(parent);
  211. if(menu.find("li:not(.custom-menu)").length && !menu.find(".divider").length) {
  212. this.add_menu_divider(menu);
  213. }
  214. return $('<li class="custom-menu"><a><i class="'
  215. +icon+'"></i> '+label+'</a></li>')
  216. .insertBefore(menu.find(".divider"))
  217. .find("a")
  218. .click(function() {
  219. click();
  220. });
  221. },
  222. add_label: function(label) {
  223. this.show_toolbar();
  224. return $("<label style='margin-top: 0.8%; margin-left: 5px; margin-right: 5px; float: left;'>"+label+" </label>")
  225. .appendTo(this.toolbar.find(".appframe-form"));
  226. },
  227. add_select: function(label, options) {
  228. var field = this.add_field({label:label, fieldtype:"Select"})
  229. return field.$wrapper.find("select").empty().add_options(options);
  230. },
  231. add_data: function(label) {
  232. var field = this.add_field({label: label, fieldtype: "Data"});
  233. return field.$wrapper.find("input").attr("placeholder", label);
  234. },
  235. add_date: function(label, date) {
  236. var field = this.add_field({label: label, fieldtype: "Date", "default": date});
  237. return field.$wrapper.find("input").attr("placeholder", label);
  238. },
  239. add_check: function(label) {
  240. this.show_toolbar();
  241. return $("<div class='checkbox' style='margin-right: 10px; margin-top: 7px; float: left;'><label><input type='checkbox'>" + label + "</label></div>")
  242. .appendTo(this.toolbar.find(".appframe-form"))
  243. .find("input");
  244. },
  245. add_field: function(df) {
  246. this.show_toolbar();
  247. var f = wn.ui.form.make_control({
  248. df: df,
  249. parent: this.toolbar.find(".appframe-form"),
  250. only_input: true,
  251. })
  252. f.refresh();
  253. $(f.wrapper)
  254. .addClass('col-md-2')
  255. .css({
  256. "padding-left": "0px",
  257. "padding-right": "0px",
  258. "margin-right": "5px"
  259. })
  260. .attr("title", wn._(df.label)).tooltip();
  261. f.$input.attr("placeholder", wn._(df.label));
  262. if(df["default"])
  263. f.set_input(df["default"])
  264. this.fields_dict[df.fieldname || df.label] = f;
  265. return f;
  266. },
  267. add_ripped_paper_effect: function(wrapper) {
  268. if(!wrapper) var wrapper = wn.container.page;
  269. var layout_main = $(wrapper).find('.layout-main');
  270. if(!layout_main.length) {
  271. layout_main = $(wrapper).find('.layout-main-section');
  272. }
  273. layout_main.css({"padding-top":"25px"});
  274. $('<div class="ripped-paper-border"></div>')
  275. .prependTo(layout_main)
  276. .css({"width": $(layout_main).width()});
  277. },
  278. /* deprecated */
  279. clear_breadcrumbs: function() {
  280. this.$w.find(".breadcrumb").empty();
  281. },
  282. add_breadcrumb: function(icon, link, title) {
  283. return; // bc
  284. },
  285. add_home_breadcrumb: function() {
  286. this.add_breadcrumb("icon-home", wn.home_page, "Home");
  287. },
  288. add_list_breadcrumb: function(doctype) {
  289. this.add_breadcrumb("icon-list", "List/" + encodeURIComponent(doctype), doctype + " List");
  290. },
  291. });
  292. // parent, title, single_column
  293. // standard page with appframe
  294. wn.ui.make_app_page = function(opts) {
  295. /* help: make a standard page layout with a toolbar and title */
  296. /* options: [
  297. "parent: [HTMLElement] parent element",
  298. "single_column: [Boolean] false/true",
  299. "title: [optional] set this title"
  300. ]
  301. */
  302. if(opts.single_column) {
  303. $('<div class="appframe col-md-12">\
  304. <div class="layout-appframe row"></div>\
  305. <div class="layout-main"></div>\
  306. </div>').appendTo(opts.parent);
  307. } else {
  308. $('<div class="appframe col-md-12">\
  309. <div class="layout-appframe row"></div>\
  310. <div class="row">\
  311. <div class="layout-main-section col-md-9"></div>\
  312. <div class="layout-side-section col-md-3"></div>\
  313. </div>\
  314. </div>').appendTo(opts.parent);
  315. }
  316. opts.parent.appframe = new wn.ui.AppFrame($(opts.parent).find('.layout-appframe'));
  317. if(opts.set_document_title!==undefined)
  318. opts.parent.appframe.set_document_title = opts.set_document_title;
  319. if(opts.title) opts.parent.appframe.set_title(opts.title);
  320. if(opts.icon) opts.parent.appframe.add_module_icon(null, opts.icon);
  321. }