您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

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