API Docs for: 0.25.0
Show:

File: addon/mixins/taggable-mixin.js

  1. import Ember from 'ember';
  2.  
  3. /**
  4. * @module ember-osf
  5. * @submodule mixins
  6. */
  7.  
  8. /**
  9. * Controller mixin that implements basic tagging functionality. Uses the model defined in the model hook.
  10. * @class TaggableMixin
  11. * @extends Ember.Mixin
  12. */
  13. export default Ember.Mixin.create({
  14. actions: {
  15. /**
  16. * Appends a tag to the current array of tags on the resource. Copies current
  17. * list of tags, appends new tag to copy, and then sets tags on the resource
  18. * as the modified copy.
  19. *
  20. * @method addATag
  21. * @param {DS.Model} model A model instance that supports tags functionality
  22. * @param {String} tag New tag to be added to list.
  23. */
  24. addATag(model, tag) {
  25. var currentTags = model.get('tags').slice(0);
  26. Ember.A(currentTags);
  27. currentTags.pushObject(tag);
  28. model.set('tags', currentTags);
  29. return model.save();
  30. },
  31. /**
  32. * Removes a tag from the current array of tags on the resource.
  33. *
  34. * @method removeATag
  35. * @param {DS.Model} model A model instance that supports tags functionality
  36. * @param {String} tag Tag to be removed from list.
  37. */
  38. removeATag(model, tag) {
  39. var currentTags = model.get('tags').slice(0);
  40. currentTags.splice(currentTags.indexOf(tag), 1);
  41. model.set('tags', currentTags);
  42. model.save();
  43. }
  44. }
  45. });
  46.