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.
 
 
 
 
 
 

85 lines
2.2 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) {
  8. return "<div style='text-align: right'>" + flt(value, 6) + "</div>";
  9. },
  10. Int: function(value) {
  11. return cint(value);
  12. },
  13. Currency: function(value) {
  14. return "<div style='text-align: right'>" + fmt_money(value) + "</div>";
  15. },
  16. Check: function(value) {
  17. return value ? "<i class='icon-ok'></i>" : "<i class='icon'></i>";
  18. },
  19. Link: function(value, docfield) {
  20. if(!value) return "";
  21. if(docfield && docfield.options) {
  22. return repl('<a href="#Form/%(doctype)s/%(name)s">\
  23. <i class="icon icon-share" title="Open %(name)s" \
  24. style="margin-top:-1px"></i></a> %(name)s', {
  25. doctype: docfield.options,
  26. name: value
  27. });
  28. } else {
  29. return value;
  30. }
  31. },
  32. Date: function(value) {
  33. return dateutil.str_to_user(value);
  34. },
  35. Text: function(value) {
  36. if(value) {
  37. var tags = ["<p[^>]>", "<div[^>]>", "<br[^>]>"];
  38. var match = false;
  39. for(var i=0; i<tags.length; i++) {
  40. if(value.match(tags[i])) {
  41. match = true;
  42. }
  43. }
  44. if(!match) {
  45. return replace_newlines(value);
  46. }
  47. }
  48. return wn.form.formatters.Data(value);
  49. },
  50. Tag: function(value) {
  51. var html = "";
  52. $.each((value || "").split(","), function(i, v) {
  53. if(v) html+= '<span class="label label-info" \
  54. style="margin-right: 7px; cursor: pointer;"\
  55. data-field="_user_tags" data-label="'+v+'">'+v +'</span>';
  56. });
  57. return html;
  58. },
  59. SmallText: function(value) {
  60. return wn.form.formatters.Text(value);
  61. },
  62. WorkflowState: function(value) {
  63. workflow_state = wn.meta.get("Workflow State", value)[0];
  64. if(workflow_state) {
  65. return repl("<span class='label label-%(style)s' \
  66. data-workflow-state='%(value)s'\
  67. style='padding-bottom: 4px; cursor: pointer;'>\
  68. <i class='icon-small icon-white icon-%(icon)s'></i> %(value)s</span>", {
  69. value: value,
  70. style: workflow_state.style.toLowerCase(),
  71. icon: workflow_state.icon
  72. });
  73. } else {
  74. return "<span class='label'>" + value + "</span>";
  75. }
  76. }
  77. }
  78. wn.form.get_formatter = function(fieldtype) {
  79. return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
  80. }