您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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