Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 
 
 

353 wiersze
9.4 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">&nbsp;</div>\
  20. <div class="status-bar"></div>\
  21. </div>\
  22. </div>\
  23. <div class="info-bar" style="display: none;"><ul class="hidden-sm-inline"></ul></div>\
  24. <div class="navbar" style="display: none;">\
  25. <div class="navbar-form pull-left">\
  26. <div class="btn-group"></div>\
  27. </div>\
  28. </div>\
  29. <div>').prependTo(parent);
  30. this.$w.find('.close').click(function() {
  31. window.history.back();
  32. })
  33. this.toolbar = this.$w.find(".navbar-form");
  34. if(title)
  35. this.set_title(title);
  36. },
  37. get_title_area: function() {
  38. return this.$w.find(".title-area");
  39. },
  40. set_title: function(txt, full_text) {
  41. this.title = txt;
  42. document.title = txt;
  43. this.$w.find(".breadcrumb .appframe-title").html(txt);
  44. this.$w.find(".title-text").html(txt);
  45. },
  46. set_sub_title: function(txt) {
  47. this.$w.find(".sub-title-area").html(txt);
  48. },
  49. add_infobar: function(label, onclick) {
  50. var $ul = this.$w.find(".info-bar").toggle(true).find("ul"),
  51. $li = $('<li><a href="#">' + label + '</a></li>')
  52. .appendTo($ul)
  53. .click(function() {
  54. onclick();
  55. return false;
  56. })
  57. return $li;
  58. },
  59. clear_infobar: function() {
  60. this.$w.find(".info-bar").toggle(false).find("ul").empty();
  61. },
  62. add_module_icon: function(module) {
  63. var module_info = wn.modules[module];
  64. if(!module_info) {
  65. module_info = {
  66. icon: "icon-question-sign",
  67. color: "#eeeeee"
  68. }
  69. }
  70. if(module_info && module_info.icon) {
  71. this.$w.find(".title-icon").html('<i class="'
  72. +module_info.icon+'"></i> ')
  73. .toggle(true)
  74. .css({
  75. "background-color": module_info.color,
  76. })
  77. .attr("module-name", module)
  78. .click(function() {
  79. var module_info = wn.modules[$(this).attr("module-name")];
  80. wn.set_route(module_info ? module_info.link : "desktop");
  81. });
  82. }
  83. },
  84. set_views_for: function(doctype, active_view) {
  85. this.doctype = doctype;
  86. var me = this,
  87. meta = locals.DocType[doctype],
  88. views = [],
  89. module_info = wn.modules[meta.module];
  90. if(module_info) {
  91. views.push({
  92. icon: module_info.icon,
  93. route: module_info.link,
  94. type: "module"
  95. })
  96. }
  97. views.push({
  98. icon: "icon-file-alt",
  99. route: "",
  100. type: "form",
  101. set_route: function() {
  102. if(wn.views.formview[me.doctype]) {
  103. wn.set_route("Form", me.doctype, wn.views.formview[me.doctype].frm.docname);
  104. } else {
  105. new_doc(doctype);
  106. }
  107. }
  108. });
  109. if(!meta.issingle) {
  110. views.push({
  111. icon: "icon-list",
  112. route: "List/" + doctype,
  113. type: "list"
  114. });
  115. }
  116. if(wn.views.calendar[doctype]) {
  117. views.push({
  118. icon: "icon-calendar",
  119. route: "Calendar/" + doctype,
  120. type: "calendar"
  121. });
  122. }
  123. if(wn.views.calendar[doctype] && wn.views.calendar[doctype]) {
  124. views.push({
  125. icon: "icon-tasks",
  126. route: "Gantt/" + doctype,
  127. type: "gantt"
  128. });
  129. }
  130. if(wn.model.can_get_report(doctype)) {
  131. views.push({
  132. icon: "icon-table",
  133. route: "Report/" + doctype,
  134. type: "report"
  135. });
  136. }
  137. this.set_views(views, active_view);
  138. },
  139. set_views: function(views, active_view) {
  140. var me = this;
  141. $right = this.$w.find(".title-button-area");
  142. $.each(views, function(i, e) {
  143. var btn = $(repl('<button class="btn btn-default" data-route="%(route)s">\
  144. <i class="%(icon)s"></i></button>', e))
  145. .click(e.set_route || function() {
  146. window.location.hash = "#" + $(this).attr("data-route");
  147. })
  148. .css({
  149. width: "39px"
  150. })
  151. .attr("title", wn._(toTitle(e.type)))
  152. .appendTo($right);
  153. if(e.type==active_view) {
  154. btn.removeClass("btn-default").addClass("btn-info");
  155. }
  156. });
  157. },
  158. add_help_button: function(txt) {
  159. $('<button class="btn btn-default" button-type="help">\
  160. <b>?</b></button>')
  161. .data('help-text', txt)
  162. .click(function() { msgprint($(this).data('help-text'), 'Help'); })
  163. .appendTo(this.toolbar);
  164. },
  165. show_toolbar: function() {
  166. this.toolbar.parent().toggle(true);
  167. },
  168. clear_buttons: function() {
  169. this.toolbar && this.toolbar
  170. .html('<div class="btn-group"></div>')
  171. .parent()
  172. .toggle(false);
  173. $(".custom-menu").remove();
  174. },
  175. add_button: function(label, click, icon, is_title) {
  176. this.show_toolbar();
  177. args = { label: wn._(label), icon:'' };
  178. if(icon) {
  179. args.icon = '<i class="'+icon+'"></i>';
  180. }
  181. this.buttons[label] && this.buttons[label].remove();
  182. var append_or_prepend = is_title ? "prependTo" : "appendTo";
  183. this.buttons[label] = $(repl('<button class="btn btn-default">\
  184. %(icon)s <span class="hidden-sm-inline">%(label)s</span></button>', args))
  185. [append_or_prepend](this.toolbar.find(".btn-group").css({"margin-right": "5px"}))
  186. .attr("title", wn._(label))
  187. .click(click);
  188. if(is_title) {
  189. this.buttons[label].addClass("btn-title");
  190. }
  191. return this.buttons[label];
  192. },
  193. get_menu: function(label) {
  194. return $("#navbar-" + label.toLowerCase());
  195. },
  196. add_menu_divider: function(menu) {
  197. menu = typeof menu == "string" ?
  198. this.get_menu(menu) : menu;
  199. $('<li class="divider custom-menu"></li>').appendTo(menu);
  200. },
  201. add_dropdown_button: function(parent, label, click, icon) {
  202. var menu = this.get_menu(parent);
  203. if(menu.find("li:not(.custom-menu)").length && !menu.find(".divider").length) {
  204. this.add_menu_divider(menu);
  205. }
  206. return $('<li class="custom-menu"><a><i class="'
  207. +icon+'"></i> '+label+'</a></li>')
  208. .appendTo(menu)
  209. .find("a")
  210. .click(function() {
  211. click();
  212. });
  213. },
  214. add_label: function(label) {
  215. this.show_toolbar();
  216. return $("<label class='col-lg-1'>"+label+" </label>")
  217. .appendTo(this.toolbar);
  218. },
  219. add_select: function(label, options) {
  220. this.show_toolbar();
  221. return $("<select class='col-lg-2' style='margin-right: 5px;'>")
  222. .add_options(options)
  223. .appendTo(this.toolbar);
  224. },
  225. add_data: function(label) {
  226. this.show_toolbar();
  227. return $("<input class='col-lg-2' style='margin-right: 5px;' type='text' placeholder='"+ label +"'>")
  228. .appendTo(this.toolbar);
  229. },
  230. add_date: function(label, date) {
  231. this.show_toolbar();
  232. return $("<input class='col-lg-2' style='margin-right: 5px;' type='text'>").datepicker({
  233. dateFormat: sys_defaults.date_format.replace("yyyy", "yy"),
  234. changeYear: true,
  235. }).val(dateutil.str_to_user(date) || "")
  236. .appendTo(this.toolbar);
  237. },
  238. add_check: function(label) {
  239. this.show_toolbar();
  240. return $("<label style='display: inline;'><input type='checkbox' \
  241. style='margin-right: 5px;'/> " + label + "</label>")
  242. .appendTo(this.toolbar)
  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,
  250. only_input: true,
  251. })
  252. f.refresh();
  253. $(f.wrapper)
  254. .addClass('col-lg-2')
  255. .css({
  256. "display": "inline-block",
  257. "margin-top": "0px",
  258. "margin-bottom": "-17px",
  259. "margin-left": "4px"
  260. })
  261. .attr("title", df.label).tooltip();
  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 col-lg-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 col-lg-12">\
  309. <div class="layout-appframe row"></div>\
  310. <div class="row">\
  311. <div class="layout-main-section col col-lg-9"></div>\
  312. <div class="layout-side-section col col-lg-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. }