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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. wn.ui.form.Layout = Class.extend({
  2. init: function(opts) {
  3. this.ignore_types = ["Section Break", "Column Break"];
  4. $.extend(this, opts);
  5. this.make();
  6. },
  7. make: function() {
  8. this.wrapper = $('<div class="form-layout">').appendTo(this.parent);
  9. this.fields = wn.meta.docfield_list[this.doctype];
  10. this.fields.sort(function(a,b) { return a.idx - b.idx});
  11. this.render();
  12. },
  13. render: function() {
  14. var me = this;
  15. this.section = null;
  16. if(this.fields[0] && this.fields[0].fieldtype!="Section Break") {
  17. this.make_section();
  18. }
  19. $.each(this.fields, function(i, df) {
  20. switch(df.fieldtype) {
  21. case "Section Break":
  22. me.make_section(df);
  23. break;
  24. case "Column Break":
  25. break;
  26. case "Table":
  27. case "Text Editor":
  28. case "Code":
  29. case "HTML":
  30. var fieldwrapper = $('<div class="col-span-12">').appendTo(me.section);
  31. me.make_field(df, fieldwrapper);
  32. break;
  33. case "Text":
  34. var fieldwrapper = $('<div class="col-span-8">').appendTo(me.section);
  35. me.make_field(df, fieldwrapper);
  36. break;
  37. default:
  38. var fieldwrapper = $('<div class="col-span-4" \
  39. style="height: 60px; overflow: hidden;">')
  40. .appendTo(me.section);
  41. me.make_field(df, fieldwrapper);
  42. }
  43. });
  44. },
  45. make_field: function(df, parent) {
  46. var fieldobj = make_field(df, this.doctype, parent.get(0), this.frm);
  47. this.frm.fields.push(fieldobj);
  48. this.frm.fields_dict[df.fieldname] = fieldobj;
  49. },
  50. make_section: function(df) {
  51. if(this.section) {
  52. $("<hr>").appendTo(this.wrapper);
  53. }
  54. this.section = $('<div class="row">').appendTo(this.wrapper);
  55. this.frm.sections.push(this.section);
  56. if(df) {
  57. if(df.label) {
  58. $('<div class="col-span-12"><h4>' + df.label + "</h4></div>").appendTo(this.section);
  59. }
  60. if(df.description) {
  61. $('<div class="col-span-12 small muted">' + df.description + '</div>').appendTo(this.section);
  62. }
  63. this.frm.fields_dict[df.fieldname] = this.section;
  64. }
  65. return this.section;
  66. },
  67. refresh: function() {
  68. }
  69. })