Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

appframe.js 6.4 KiB

há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
há 13 anos
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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></div>').prependTo(parent);
  9. this.$titlebar = $('<div class="appframe-titlebar">\
  10. <span class="appframe-breadcrumb">\
  11. </span>\
  12. <span class="appframe-center">\
  13. <span class="appframe-title"></span>\
  14. <span class="appframe-subject"></span>\
  15. </span>\
  16. <span class="close" style="margin-top: 5px; margin-right: 7px;">&times;</span>\
  17. <span class="appframe-right btn-group">\
  18. </span>\
  19. </div>').appendTo(this.$w);
  20. this.$w.find('.close').click(function() {
  21. window.history.back();
  22. })
  23. if(title)
  24. this.set_title(title);
  25. },
  26. title: function(txt) {
  27. this.set_title(txt);
  28. },
  29. set_title: function(txt, full_text) {
  30. if(this.set_document_title)
  31. document.title = txt;
  32. this.$titlebar.find(".appframe-title").html(txt)
  33. .attr("title", full_text || txt);
  34. },
  35. clear_breadcrumbs: function() {
  36. this.$w.find(".appframe-breadcrumb").empty();
  37. },
  38. add_breadcrumb: function(icon, link, title) {
  39. if(link) {
  40. $(repl("<span><a href='#%(link)s' title='%(title)s'><i class='%(icon)s'></i>\
  41. </a></span>", {
  42. icon: icon,
  43. link: link,
  44. title: wn._(title)
  45. })).appendTo(this.$w.find(".appframe-breadcrumb"));
  46. } else {
  47. $(repl("<span><i class='%(icon)s'></i></span>", {
  48. icon: icon,
  49. })).appendTo(this.$w.find(".appframe-breadcrumb"));
  50. }
  51. },
  52. add_home_breadcrumb: function() {
  53. this.add_breadcrumb("icon-home", wn.home_page, "Home");
  54. },
  55. add_list_breadcrumb: function(doctype) {
  56. this.add_breadcrumb("icon-list", "List/" + encodeURIComponent(doctype), doctype + " List");
  57. },
  58. add_module_breadcrumb: function(module) {
  59. var module_info = wn.modules[module];
  60. if(module_info) {
  61. this.add_breadcrumb(module_info.icon, module_info.link,
  62. module_info.label || module);
  63. }
  64. },
  65. set_views_for: function(doctype, active_view) {
  66. this.doctype = doctype;
  67. var me = this;
  68. var views = [{
  69. icon: "icon-file-alt",
  70. route: "",
  71. type: "form",
  72. set_route: function() {
  73. if(wn.views.formview[me.doctype]) {
  74. wn.set_route("Form", me.doctype, wn.views.formview[me.doctype].frm.docname);
  75. } else {
  76. new_doc(doctype);
  77. }
  78. }
  79. }];
  80. if(!locals.DocType[doctype].issingle) {
  81. views.push({
  82. icon: "icon-list",
  83. route: "List/" + doctype,
  84. type: "list"
  85. });
  86. }
  87. if(locals.DocType[doctype].__calendar_js) {
  88. views.push({
  89. icon: "icon-calendar",
  90. route: "Calendar/" + doctype,
  91. type: "calendar"
  92. });
  93. }
  94. if(wn.model.can_get_report(doctype)) {
  95. views.push({
  96. icon: "icon-table",
  97. route: "Report2/" + doctype,
  98. type: "report"
  99. });
  100. }
  101. this.set_views(views, active_view);
  102. },
  103. set_views: function(views, active_view) {
  104. var me = this;
  105. $right = this.$w.find(".appframe-right").css({
  106. "display":"inline-block",
  107. "width": (39 * views.length) + "px"
  108. });
  109. $.each(views, function(i, e) {
  110. var btn = $(repl('<button class="btn" data-route="%(route)s">\
  111. <i class="%(icon)s"></i></button>', e))
  112. .click(e.set_route || function() {
  113. window.location.hash = "#" + $(this).attr("data-route");
  114. })
  115. .css({
  116. width: "39px"
  117. })
  118. .attr("title", wn._(toTitle(e.type)))
  119. .appendTo($right);
  120. if(e.type==active_view) {
  121. btn.addClass("btn-inverse");
  122. }
  123. });
  124. },
  125. add_button: function(label, click, icon) {
  126. this.add_toolbar();
  127. args = { label: label, icon:'' };
  128. if(icon) {
  129. args.icon = '<i class="'+icon+'"></i>';
  130. }
  131. this.buttons[label] = $(repl('<button class="btn">\
  132. %(icon)s %(label)s</button>', args))
  133. .click(click)
  134. .appendTo(this.toolbar);
  135. return this.buttons[label];
  136. },
  137. add_help_button: function(txt) {
  138. this.add_toolbar();
  139. $('<button class="btn" button-type="help">\
  140. <b>?</b></button>')
  141. .data('help-text', txt)
  142. .click(function() { msgprint($(this).data('help-text'), 'Help'); })
  143. .appendTo(this.toolbar);
  144. },
  145. clear_buttons: function() {
  146. this.toolbar && this.toolbar.empty();
  147. },
  148. add_toolbar: function() {
  149. if(!this.toolbar)
  150. this.$w.append('<div class="appframe-toolbar"><div class="btn-group"></div></div>');
  151. this.toolbar = this.$w.find('.appframe-toolbar .btn-group');
  152. },
  153. add_label: function(label) {
  154. return $("<span class='label'>"+label+" </span>").appendTo(this.toolbar.parent());
  155. },
  156. add_select: function(label, options) {
  157. this.add_toolbar();
  158. return $("<select style='width: 100px;'>")
  159. .add_options(options).appendTo(this.toolbar.parent());
  160. },
  161. add_data: function(label) {
  162. this.add_toolbar();
  163. return $("<input style='width: 100px;' type='text' placeholder='"+ label +"'>")
  164. .appendTo(this.toolbar.parent());
  165. },
  166. add_date: function(label, date) {
  167. this.add_toolbar();
  168. return $("<input style='width: 80px;' type='text'>").datepicker({
  169. dateFormat: sys_defaults.date_format.replace("yyyy", "yy"),
  170. changeYear: true,
  171. }).val(dateutil.str_to_user(date) || "").appendTo(this.toolbar.parent());
  172. },
  173. add_check: function(label) {
  174. this.add_toolbar();
  175. return $("<label style='display: inline;'><input type='checkbox' \
  176. style='margin-top: -2px;'/> " + label + "</label>")
  177. .appendTo(this.toolbar.parent())
  178. .find("input");
  179. },
  180. add_ripped_paper_effect: function(wrapper) {
  181. if(!wrapper) var wrapper = wn.container.page;
  182. var layout_main = $(wrapper).find('.layout-main');
  183. if(!layout_main.length) {
  184. layout_main = $(wrapper).find('.layout-main-section');
  185. }
  186. layout_main.css({"padding-top":"25px"});
  187. $('<div class="ripped-paper-border"></div>')
  188. .prependTo(layout_main)
  189. .css({"width": $(layout_main).width()});
  190. }
  191. });
  192. // parent, title, single_column
  193. // standard page with appframe
  194. wn.ui.make_app_page = function(opts) {
  195. if(opts.single_column) {
  196. $(opts.parent).html('<div class="layout-wrapper layout-wrapper-appframe">\
  197. <div class="layout-appframe"></div>\
  198. <div class="layout-main"></div>\
  199. </div>');
  200. } else {
  201. $(opts.parent).html('<div class="layout-wrapper layout-wrapper-background">\
  202. <div class="layout-appframe"></div>\
  203. <div class="layout-main-section"></div>\
  204. <div class="layout-side-section"></div>\
  205. <div class="clear"></div>\
  206. </div>');
  207. }
  208. opts.parent.appframe = new wn.ui.AppFrame($(opts.parent).find('.layout-appframe'));
  209. if(opts.set_document_title!==undefined)
  210. opts.parent.appframe.set_document_title = opts.set_document_title;
  211. if(opts.title) opts.parent.appframe.title(opts.title);
  212. }