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.
 
 
 
 
 
 

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