You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

appframe.js 8.5 KiB

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