PageRenderTime 47ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/client/src/main/webapp/js/collections/Collection.js

https://bitbucket.org/sugardave/ozp-commons
JavaScript | 51 lines | 17 code | 7 blank | 27 comment | 1 complexity | c867f9e7123ec172e2219b32629c7a5a MD5 | raw file
  1. /*
  2. * Copyright 2013 Next Century Corporation
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. define([
  17. 'backbone'
  18. ],
  19. function(Backbone) {
  20. 'use strict';
  21. var Collection = Backbone.Collection.extend({
  22. /**
  23. * Reorders the collection so that the
  24. * specified model is at the specified index.
  25. * Relative ordering of all other models is preserved.
  26. * In the case where the model being moved was previously
  27. * at a lower index, the element that was at the newIndex
  28. * will end up before the model being moved.
  29. *
  30. * @param model The model to move
  31. * @param newIndex The desired index of the model
  32. * @fires reorder (model, newIndex) Upon completion
  33. */
  34. updateIndex: function(model, newIndex) {
  35. if (!this.contains(model)) {
  36. return;
  37. }
  38. this.remove(model, {silent: true});
  39. this.add(model, {at: newIndex, silent: true});
  40. this.trigger('reorder', model, newIndex);
  41. }
  42. });
  43. return Collection;
  44. });