PageRenderTime 41ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/gaoqi-py/static/js/module/tag-sel/activity-tags.js

https://bitbucket.org/bobyuxinyang/letsgaoqi
JavaScript | 54 lines | 50 code | 4 blank | 0 comment | 3 complexity | 7a8401cf36879bf361941dbdeb9b3a53 MD5 | raw file
  1. define(function(require){
  2. var service = require('utility/service');
  3. require('module/tag-sel/activity-tag');
  4. window.activity_tags = Backbone.Collection.extend({
  5. model: activity_tag,
  6. choosedTags: [],
  7. initialize: function () {
  8. this.getAll();
  9. this.bind('choose-status-changed', this.chooseStatusChanged);
  10. },
  11. comparator: function (e) {
  12. return e.get("index");
  13. },
  14. getAll: function () {
  15. var $self = this;
  16. service.get_all_activity_tags(function (e) {
  17. $self._reset();
  18. $self.add(e);
  19. $self.trigger('getAll');
  20. });
  21. },
  22. chooseStatusChanged: function(model, isChoosed) {
  23. var $self = this;
  24. if (isChoosed) {
  25. this.choosedTags.push(model.attributes);
  26. var len = this.choosedTags.length;
  27. this.choosedTags[len - 1].order = len;
  28. }else{
  29. var i = 0;
  30. _.each(this.choosedTags, function (item) {
  31. if (item.name == model.attributes.name) {
  32. i = _.indexOf($self.choosedTags, item);
  33. }
  34. });
  35. this.choosedTags.splice(i, 1);
  36. }
  37. this.trigger('choosed-tags-changed', this.choosedTags);
  38. },
  39. getChoosedTags: function () {
  40. return this.choosedTags;
  41. },
  42. setChoosedTags: function (models){
  43. var $self = this;
  44. this.choosedTags = [];
  45. _.each(models, function (model) {
  46. $self.choosedTags.push(model.attributes);
  47. });
  48. }
  49. });
  50. })