PageRenderTime 53ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/auiplugin-tests/src/main/resources/restfultable/restfultable-example.js

https://bitbucket.org/jwalton/aui-archive
JavaScript | 97 lines | 85 code | 10 blank | 2 comment | 0 complexity | b1162d4b29954472e27f265302b4a030 MD5 | raw file
  1. (function ($) {
  2. var EditGroupView = AJS.RestfulTable.CustomEditView.extend({
  3. render: function (self) {
  4. var $select = $("<select name='group' class='select'>" +
  5. "<option value='Friends'>Friends</option>" +
  6. "<option value='Family'>Family</option>" +
  7. "<option value='Work'>Work</option>" +
  8. "</select>");
  9. $select.val(self.value); // select currently selected
  10. return $select;
  11. }
  12. });
  13. var NameReadView = AJS.RestfulTable.CustomReadView.extend({
  14. render: function (self) {
  15. return $("<strong />").text(self.value);
  16. }
  17. });
  18. var CheckboxEditView = AJS.RestfulTable.CustomEditView.extend({
  19. render: function (self) {
  20. console.log(self);
  21. var $select = $("<input type='checkbox' class='ajs-restfultable-input-" + self.name + "' />" +
  22. "<input type='hidden' name='" + self.name + "'/>");
  23. return $select;
  24. }
  25. });
  26. var DummyReadView = AJS.RestfulTable.CustomReadView.extend({
  27. render: function (self) {
  28. return $("<strong />").text("Blah");
  29. }
  30. });
  31. // DOM ready
  32. $(function () {
  33. var auiEvents = ["ROW_ADDED", "REORDER_SUCCESS", "ROW_REMOVED", "EDIT_ROW"];
  34. _.each(auiEvents, function(eventName){
  35. $(AJS).one(AJS.RestfulTable.Events[eventName], function(){
  36. AJS.messages.info("#message-area", {
  37. id: eventName,
  38. title: "test",
  39. body: eventName + " fired on AJS. Used for testing AJS events."
  40. });
  41. });
  42. });
  43. var url = AJS.contextPath() + "/rest/contacts/1.0/contacts",
  44. $contactsTable = $("#contacts-table"),
  45. $contactsAddPositionBottomTable = $("#contacts-table-addPositionBottom");;
  46. new AJS.RestfulTable({
  47. el: $contactsTable, // <table>
  48. autofocus: true, // auto focus first field of create row
  49. columns: [
  50. {id: "name", header: "Name", readView: NameReadView}, // id is the mapping of the rest property to render
  51. {id: "group", header: "Group", editView: EditGroupView}, // header is the text in the <th>
  52. {id: "number", header: "Number"},
  53. {id: "checkbox", header: "Checkbox", readView: DummyReadView, editView: CheckboxEditView}
  54. ],
  55. resources: {
  56. all: url, // resource to get all contacts
  57. self: url // resource to get single contact url/{id}
  58. },
  59. noEntriesMsg: "You have no contacts. Loner!", // message to be displayed when table is empty
  60. allowReorder: true, // drag and drop reordering
  61. fieldFocusSelector: function(name) {
  62. return ":input[type!=hidden][name=" + name + "], #" + name + ", .ajs-restfultable-input-" + name;
  63. }
  64. });
  65. // duplicate of the first table but with the addPosition: "bottom" option applied.
  66. new AJS.RestfulTable({
  67. el: $contactsAddPositionBottomTable, // <table>
  68. autofocus: true, // auto focus first field of create row
  69. columns: [
  70. {id: "name", header: "Name", readView: NameReadView}, // id is the mapping of the rest property to render
  71. {id: "group", header: "Group", editView: EditGroupView}, // header is the text in the <th>
  72. {id: "number", header: "Number"},
  73. {id: "checkbox", header: "Checkbox", readView: DummyReadView, editView: CheckboxEditView}
  74. ],
  75. resources: {
  76. all: url, // resource to get all contacts
  77. self: url // resource to get single contact url/{id}
  78. },
  79. noEntriesMsg: "You have no contacts. Loner!", // message to be displayed when table is empty
  80. allowReorder: true, // drag and drop reordering
  81. fieldFocusSelector: function(name) {
  82. return ":input[type!=hidden][name=" + name + "], #" + name + ", .ajs-restfultable-input-" + name;
  83. },
  84. addPosition: "bottom"
  85. });
  86. });
  87. })(AJS.$);