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.
 
 
 
 
 
 

73 line
2.1 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 flt(value, 6);
  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 && value.indexOf("<br>")==-1 && value.indexOf("<p>")==-1 && value.indexOf("<div")==-1)
  37. return replace_newlines(value);
  38. return wn.form.formatters.Data(value);
  39. },
  40. Tag: function(value) {
  41. var html = "";
  42. $.each((value || "").split(","), function(i, v) {
  43. if(v) html+= '<span class="label label-info" \
  44. style="margin-right: 7px; cursor: pointer;"\
  45. data-field="_user_tags" data-label="'+v+'">'+v +'</span>';
  46. });
  47. return html;
  48. },
  49. SmallText: function(value) {
  50. return wn.formatters.Text(value);
  51. },
  52. WorkflowState: function(value) {
  53. workflow_state = wn.meta.get("Workflow State", value)[0];
  54. if(workflow_state) {
  55. return repl("<span class='label label-%(style)s' \
  56. data-workflow-state='%(value)s'\
  57. style='padding-bottom: 4px; cursor: pointer;'>\
  58. <i class='icon-small icon-white icon-%(icon)s'></i> %(value)s</span>", {
  59. value: value,
  60. style: workflow_state.style.toLowerCase(),
  61. icon: workflow_state.icon
  62. });
  63. } else {
  64. return "<span class='label'>" + value + "</span>";
  65. }
  66. }
  67. }
  68. wn.form.get_formatter = function(fieldtype) {
  69. return wn.form.formatters[fieldtype.replace(/ /g, "")] || wn.form.formatters.Data;
  70. }