Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 
 
 

364 Zeilen
10 KiB

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