form-x-editable.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //[Javascript]
  2. $(function () {
  3. "use strict";
  4. $(function() {
  5. //editables
  6. $('#username').editable({
  7. type: 'text',
  8. pk: 1,
  9. name: 'username',
  10. title: 'Enter username'
  11. });
  12. $('#firstname').editable({
  13. validate: function(value) {
  14. if ($.trim(value) == '') return 'This field is required';
  15. }
  16. });
  17. $('#sex').editable({
  18. prepend: "not selected",
  19. source: [{
  20. value: 1,
  21. text: 'Male'
  22. }, {
  23. value: 2,
  24. text: 'Female'
  25. }],
  26. display: function(value, sourceData) {
  27. var colors = {
  28. "": "#98a6ad",
  29. 1: "#5fbeaa",
  30. 2: "#5d9cec"
  31. },
  32. elem = $.grep(sourceData, function(o) {
  33. return o.value == value;
  34. });
  35. if (elem.length) {
  36. $(this).text(elem[0].text).css("color", colors[value]);
  37. } else {
  38. $(this).empty();
  39. }
  40. }
  41. });
  42. $('#status').editable();
  43. $('#group').editable({
  44. showbuttons: false
  45. });
  46. $('#dob').editable();
  47. $('#comments').editable({
  48. showbuttons: 'bottom'
  49. });
  50. //inline
  51. $('#inline-username').editable({
  52. type: 'text',
  53. pk: 1,
  54. name: 'username',
  55. title: 'Enter username',
  56. mode: 'inline'
  57. });
  58. $('#inline-firstname').editable({
  59. validate: function(value) {
  60. if ($.trim(value) == '') return 'This field is required';
  61. },
  62. mode: 'inline'
  63. });
  64. $('#inline-sex').editable({
  65. prepend: "not selected",
  66. mode: 'inline',
  67. source: [{
  68. value: 1,
  69. text: 'Male'
  70. }, {
  71. value: 2,
  72. text: 'Female'
  73. }],
  74. display: function(value, sourceData) {
  75. var colors = {
  76. "": "#98a6ad",
  77. 1: "#5fbeaa",
  78. 2: "#5d9cec"
  79. },
  80. elem = $.grep(sourceData, function(o) {
  81. return o.value == value;
  82. });
  83. if (elem.length) {
  84. $(this).text(elem[0].text).css("color", colors[value]);
  85. } else {
  86. $(this).empty();
  87. }
  88. }
  89. });
  90. $('#inline-status').editable({
  91. mode: 'inline'
  92. });
  93. $('#inline-group').editable({
  94. showbuttons: false,
  95. mode: 'inline'
  96. });
  97. $('#inline-dob').editable({
  98. mode: 'inline'
  99. });
  100. $('#inline-comments').editable({
  101. showbuttons: 'bottom',
  102. mode: 'inline'
  103. });
  104. });
  105. }); // End of use strict