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.
 
 
 
 
 
 

98 line
2.6 KiB

  1. // for license information please see license.txt
  2. wn.provide("wn.form.formatters");
  3. wn.form.formatters = {
  4. Data: function(value) {
  5. return value==null ? "" : value
  6. },
  7. Float: function(value, docfield) {
  8. var decimals = wn.boot.sysdefaults.float_precision ?
  9. parseInt(wn.boot.sysdefaults.float_precision) : null;
  10. return "<div style='text-align: right'>" +
  11. format_number(flt(value, decimals), null, decimals) + "</div>";
  12. },
  13. Int: function(value) {
  14. return cint(value);
  15. },
  16. Currency: function(value, docfield, doc) {
  17. var currency = wn.meta.get_field_currency(docfield, doc);
  18. return "<div style='text-align: right'>" + format_currency(value, currency) + "</div>";
  19. },
  20. Check: function(value) {
  21. return value ? "<i class='icon-check'></i>" : "<i class='icon-check-empty'></i>";
  22. },
  23. Link: function(value, docfield, options) {
  24. if(options && options.for_print)
  25. return value;
  26. if(!value)
  27. return "";
  28. if(docfield && docfield.options) {
  29. return repl('<a href="#Form/%(doctype)s/%(name)s">%(name)s</a>', {
  30. doctype: docfield.options,
  31. name: value
  32. });
  33. } else {
  34. return value;
  35. }
  36. },
  37. Date: function(value) {
  38. return dateutil.str_to_user(value);
  39. },
  40. Text: function(value) {
  41. if(value) {
  42. var tags = ["<p[^>]>", "<div[^>]>", "<br[^>]>"];
  43. var match = false;
  44. for(var i=0; i<tags.length; i++) {
  45. if(value.match(tags[i])) {
  46. match = true;
  47. }
  48. }
  49. if(!match) {
  50. return replace_newlines(value);
  51. }
  52. }
  53. return wn.form.formatters.Data(value);
  54. },
  55. Tag: function(value) {
  56. var html = "";
  57. $.each((value || "").split(","), function(i, v) {
  58. if(v) html+= '<span class="label label-info" \
  59. style="margin-right: 7px; cursor: pointer;"\
  60. data-field="_user_tags" data-label="'+v+'">'+v +'</span>';
  61. });
  62. return html;
  63. },
  64. SmallText: function(value) {
  65. return wn.form.formatters.Text(value);
  66. },
  67. WorkflowState: function(value) {
  68. workflow_state = wn.model.get("Workflow State", value)[0];
  69. if(workflow_state) {
  70. return repl("<span class='label label-%(style)s' \
  71. data-workflow-state='%(value)s'\
  72. style='padding-bottom: 4px; cursor: pointer;'>\
  73. <i class='icon-small icon-white icon-%(icon)s'></i> %(value)s</span>", {
  74. value: value,
  75. style: workflow_state.style.toLowerCase(),
  76. icon: workflow_state.icon
  77. });
  78. } else {
  79. return "<span class='label'>" + value + "</span>";
  80. }
  81. }
  82. }
  83. wn.form.get_formatter = function(fieldtype) {
  84. if(!fieldtype) fieldtype = "Data";
  85. return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
  86. }
  87. wn.format = function(value, df, options) {
  88. if(!df) df = {"fieldtype":"Data"};
  89. return wn.form.get_formatter(df.fieldtype)(value, df, options);
  90. }