Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.
 
 
 
 
 
 

352 рядки
9.7 KiB

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