/learn-portlet/src/main/webapp/js2.0/lesson-designer/_Lesson.js

https://github.com/ViLPy/JSCORM · JavaScript · 151 lines · 144 code · 7 blank · 0 comment · 4 complexity · d83aba86565e33568eca018a35a2cb4c MD5 · raw file

  1. var _Lesson = {};
  2. _Lesson.service = new Backbone.Service({
  3. url: path.root,
  4. sync: {
  5. create: {
  6. 'path': path.api.quiz,
  7. 'data': function () {
  8. return {
  9. action: 'ADD',
  10. courseId: Utils.getCourseId()
  11. }
  12. },
  13. 'method': 'post'
  14. },
  15. update: {
  16. path: path.api.quiz,
  17. 'data': function () {
  18. return {
  19. action: 'UPDATE',
  20. courseId: Utils.getCourseId()
  21. }
  22. },
  23. 'method': 'post'
  24. }
  25. },
  26. targets: {
  27. publish: {
  28. 'path': path.api.quiz,
  29. 'data': function (model) {
  30. return {
  31. action: 'PUBLISH',
  32. id: model.id,
  33. courseId: Utils.getCourseId()
  34. }
  35. },
  36. 'method': 'post'
  37. },
  38. clone: {
  39. 'path': path.api.quiz,
  40. 'data': function (model) {
  41. return {
  42. action: 'CLONE',
  43. id: model.id,
  44. courseId: Utils.getCourseId()
  45. }
  46. },
  47. 'method': 'post'
  48. },
  49. deleteLesson: {
  50. 'path': path.api.quiz,
  51. 'data': function (model) {
  52. return {
  53. action: 'DELETE',
  54. id: model.id,
  55. courseId: Utils.getCourseId()
  56. }
  57. },
  58. 'method': 'post'
  59. },
  60. updateLogo: {
  61. 'path': path.api.quiz,
  62. 'data': function (model) {
  63. return {
  64. action: 'UPDATELOGO',
  65. id: model.id,
  66. courseId: Utils.getCourseId()
  67. }
  68. },
  69. 'method': 'post'
  70. }
  71. }
  72. });
  73. _Lesson.Model = Backbone.Model.extend(_Lesson.service);
  74. _Lesson.Collection = Backbone.Collection.extend({
  75. model: _Lesson.Model
  76. });
  77. _Lesson.View = _LessonDefaultView.extend({
  78. tagName: 'li',
  79. className: 'tile s-12 m-4 l-2',
  80. templateSelector: '#lesson-item',
  81. events: {
  82. 'click .js-download-tincan-lesson': function() { this._downloadLesson('tincan'); },
  83. 'click .js-download-scorm-lesson': function () { this._downloadLesson('scorm'); },
  84. 'click .js-edit-lesson-info': function () { _LessonDesigner.config.eventAggregator.trigger('modals:show:editLessonInfoView', this.model); },
  85. 'click .js-edit-lesson-content': function () { _LessonDesigner.config.eventAggregator.trigger('modals:show:editLessonContentView', this.model); },
  86. 'click .js-delete-lesson': 'confirmDeleteLesson',
  87. 'click .js-process-tincan': function() { contentManagerEvent.trigger('modals:show:processTinCan', this.model); },
  88. 'click .js-publish-scorm-lesson': function() { this._publishLesson('scorm') },
  89. 'click .js-clone-lesson': function() { this.model.clone().then(function () { _LessonDesigner.config.eventAggregator.trigger('_LessonDesignerModel:fetchRequired'); }) },
  90. 'click .js-export-lesson': function () { window.location = path.root + path.api.files + 'export/?action=EXPORT&contentType=lesson' + '&id=' + this.model.id; }
  91. },
  92. confirmDeleteLesson: function () {
  93. var confirmationDialog = new ToastrDeleteConfirmation({language: GLOBAL_translations, title: GLOBAL_translations['deleteConfirmationTitle']});
  94. this.listenTo(confirmationDialog, 'deleteConfirmed', this.deleteLesson);
  95. confirmationDialog.show();
  96. },
  97. deleteLesson: function () {
  98. this.model.deleteLesson().then(function () {
  99. toastr.success(GLOBAL_translations['overlayCompleteMessageLabel']);
  100. _LessonDesigner.config.eventAggregator.trigger('_LessonDesignerModel:fetchRequired');
  101. }, function () {
  102. toastr.error(GLOBAL_translations['overlayFailedMessageLabel']);
  103. });
  104. },
  105. _publishLesson: function (lessonType) {
  106. toastr.info(GLOBAL_translations['overlayProcessMessageLabel']);
  107. this.model.publish({publishType: lessonType}).then(function (response) {
  108. if (response.status) {
  109. toastr.success(GLOBAL_translations['overlayCompleteMessageLabel']);
  110. } else {
  111. toastr.error(GLOBAL_translations['overlayContentNeededMessageLabel']);
  112. }
  113. }, function () {
  114. toastr.error(GLOBAL_translations['overlayFailedMessageLabel']);
  115. });
  116. },
  117. _downloadLesson: function (lessonType) {
  118. window.location = path.root + path.api.files + 'export/?action=DOWNLOAD&contentType=lesson'
  119. + '&id=' + this.model.id
  120. + '&courseId=' + Utils.getCourseId()
  121. + '&publishType=' + lessonType;
  122. }
  123. });
  124. _Lesson.CollectionView = _DefaultView.extend({
  125. tagName: 'ul',
  126. className: 'val-row',
  127. initialize: function(){
  128. this.listenTo(this.collection, 'reset', this.render);
  129. this.listenTo(this.collection, 'change:displayMode', this.toggleDisplayModeClass);
  130. this.toggleDisplayModeClass();
  131. },
  132. toggleDisplayModeClass: function(){
  133. this.$el.toggleClass('tiles', this.collection.displayMode == 'tile');
  134. this.$el.toggleClass('list', this.collection.displayMode == 'list');
  135. },
  136. render: function(){
  137. this.$el.html('');
  138. this.collection.each(this.addOne, this);
  139. return this;
  140. },
  141. addOne: function(model){
  142. this.$el.append(new _Lesson.View({model: model}).render().$el)
  143. }
  144. });