VGlossary.js 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. define([ "require", "utils/Globals", "models/BaseModel", "utils/UrlLinks" ], function(require, Globals, VBaseModel, UrlLinks) {
  2. "use strict";
  3. var VGlossary = VBaseModel.extend({
  4. urlRoot: UrlLinks.glossaryApiUrl(),
  5. defaults: {},
  6. serverSchema: {},
  7. idAttribute: "guid",
  8. initialize: function() {
  9. this.modelName = "VGlossary";
  10. },
  11. toString: function() {
  12. return this.get("name");
  13. },
  14. createEditCategory: function(options) {
  15. var type = "POST", url = UrlLinks.categoryApiUrl();
  16. return options.guid && (type = "PUT", url = UrlLinks.categoryApiUrl({
  17. guid: options.guid
  18. })), options = _.extend({
  19. contentType: "application/json",
  20. dataType: "json"
  21. }, options), this.constructor.nonCrudOperation.call(this, url, type, options);
  22. },
  23. createEditTerm: function(options) {
  24. var type = "POST", url = UrlLinks.termApiUrl();
  25. return options.guid && (type = "PUT", url = UrlLinks.termApiUrl({
  26. guid: options.guid
  27. })), options = _.extend({
  28. contentType: "application/json",
  29. dataType: "json"
  30. }, options), this.constructor.nonCrudOperation.call(this, url, type, options);
  31. },
  32. deleteCategory: function(guid, options) {
  33. var url = UrlLinks.categoryApiUrl({
  34. guid: guid
  35. });
  36. return options = _.extend({
  37. contentType: "application/json",
  38. dataType: "json"
  39. }, options), this.constructor.nonCrudOperation.call(this, url, "DELETE", options);
  40. },
  41. deleteTerm: function(guid, options) {
  42. var url = UrlLinks.termApiUrl({
  43. guid: guid
  44. });
  45. return options = _.extend({
  46. contentType: "application/json",
  47. dataType: "json"
  48. }, options), this.constructor.nonCrudOperation.call(this, url, "DELETE", options);
  49. },
  50. assignTermToEntity: function(guid, options) {
  51. var url = UrlLinks.termToEntityApiUrl(guid);
  52. return options = _.extend({
  53. contentType: "application/json",
  54. dataType: "json"
  55. }, options), this.constructor.nonCrudOperation.call(this, url, "POST", options);
  56. },
  57. assignTermToCategory: function(options) {
  58. return this.createEditCategory(options);
  59. },
  60. assignCategoryToTerm: function(options) {
  61. return this.createEditTerm(options);
  62. },
  63. assignTermToAttributes: function(options) {
  64. return this.createEditTerm(options);
  65. },
  66. removeTermFromAttributes: function(options) {
  67. return this.createEditTerm(options);
  68. },
  69. removeTermFromEntity: function(guid, options) {
  70. var url = UrlLinks.termToEntityApiUrl(guid);
  71. return options = _.extend({
  72. contentType: "application/json",
  73. dataType: "json"
  74. }, options), this.constructor.nonCrudOperation.call(this, url, "PUT", options);
  75. },
  76. removeTermFromCategory: function() {},
  77. removeCategoryFromTerm: function() {}
  78. }, {});
  79. return VGlossary;
  80. });