Guest User

Untitled

a guest
Jun 20th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1.  
  2. // ==========================================================================
  3. // ONRTestApp.isbnsController
  4. // ==========================================================================
  5. /*globals ONRTestApp*/
  6.  
  7. /**
  8.  
  9. This controller manages the creation of isbn data.
  10.  
  11. @extends SC.ArrayController
  12. @author Jeff Pittman
  13. */
  14. ONRTestApp.isbnsController = SC.ArrayController.create(
  15. /** @scope ONRTestApp.isbnsController.prototype */ {
  16.  
  17. // See comment in the versions controller about the creation of a closure.
  18. // The same logic applies here, except for isbns this time. Once isbn
  19. // records for a book have been created, the final step, creation of the actual book
  20. // record, is fired.
  21. generateCheckISBNsFunction: function(title,isbn){
  22. var me = this;
  23. return function(val){
  24. //console.log('checking ISBNs ' + title);
  25. if (val & SC.Record.READY_CLEAN){
  26. ONRTestApp.dataController.loadedRecordCount++;
  27. me._tmpRecordCache[title].pushObject(isbn);
  28. ONRTestApp.dataController.get('content')[title]['records']['isbns'].pushObject(isbn);
  29. me._tmpRecordCacheCount[title]--;
  30. if (me._tmpRecordCacheCount[title] === 0){
  31. delete me._tmpRecordCache[title]; // delete the old contents
  32. delete me._tmpRecordCacheCount[title];
  33. ONRTestApp.versionsController.createVersions(title);
  34. }
  35. return YES;
  36. }
  37. else return NO;
  38. };
  39. },
  40.  
  41. createISBNs: function(title){
  42. //console.log('createISBNs ' + title);
  43. var isbns = [];
  44. var versions = ONRTestApp.dataController.get('content')[title]['versions'];
  45. versions.forEach(function(version) {
  46. isbns.pushObjects(version['isbns']);
  47. });
  48.  
  49. console.log(isbns.get('length'));
  50.  
  51. this._tmpRecordCache[title] = [];
  52. this._tmpRecordCacheCount[title] = isbns.get('length');
  53.  
  54. for (var i=0,len=isbns.get('length'); i<len; i++){
  55. var isbn;
  56. console.log('type ' + isbns[i].type);
  57. isbn = ONRTestApp.store.createRecord(ONRTestApp.ISBN, {
  58. "key": isbns[i].key,
  59. "type": isbns[i].type,
  60. "text": isbns[i].text
  61. });
  62.  
  63. ONRTestApp.store.commitRecords();
  64.  
  65. // this.generateCheckISBNsFunction() is provided here to fire createVersions as the next
  66. // step in data creation, which will create versions of the book.
  67. isbn.addFiniteObserver('status',this,this.generateCheckISBNsFunction(title,isbn),this);
  68. }
  69. },
  70.  
  71. // See comment above, in the versions controller, about the use of _tmpRecordCache,Count.
  72. _tmpRecordCache: {},
  73. _tmpRecordCacheCount: {}
  74.  
  75. });
Add Comment
Please, Sign In to add comment