Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 
 
 

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