Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

formatters.js 2.0 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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).toFixed(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.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. WorkflowState: function(value) {
  50. workflow_state = wn.meta.get("Workflow State", value)[0];
  51. if(workflow_state) {
  52. return repl("<span class='label label-%(style)s' \
  53. data-workflow-state='%(value)s'\
  54. style='padding-bottom: 4px; cursor: pointer;'>\
  55. <i class='icon-small icon-white icon-%(icon)s'></i> %(value)s</span>", {
  56. value: value,
  57. style: workflow_state.style.toLowerCase(),
  58. icon: workflow_state.icon
  59. });
  60. } else {
  61. return "<span class='label'>" + value + "</span>";
  62. }
  63. }
  64. }
  65. wn.form.get_formatter = function(fieldtype) {
  66. return wn.form.formatters[fieldtype] || wn.form.formatters.Data;
  67. }