/learn-portlet/src/main/webapp/js2.0/learning-transcript/TranscriptModel.js

https://github.com/ViLPy/JSCORM · JavaScript · 219 lines · 176 code · 28 blank · 15 comment · 0 complexity · eb14904ba0eaa9ee00b6db7744ebac5d MD5 · raw file

  1. var TranscriptModel = Backbone.Model.extend({
  2. defaults: {
  3. }
  4. }).extend();
  5. UserCertificateCollectionService = new Backbone.Service({ url: path.root,
  6. sync: {
  7. 'read': {
  8. 'path': function () {
  9. return path.api.users
  10. + jQuery('#transcriptUserID').val()
  11. + '/certificates';
  12. },
  13. 'data': function () {
  14. return {
  15. companyID: jQuery('#transcriptCompanyID').val(),
  16. page: 0,
  17. count: 1,
  18. isOnlyPublished: true,
  19. courseId: Utils.getCourseId()
  20. }
  21. }
  22. },
  23. 'method': 'get'
  24. }
  25. });
  26. var UserCertificateCollection = Backbone.Collection.extend({
  27. model: TranscriptModel,
  28. parse: function (response) {
  29. return response.records;
  30. }
  31. }).extend(UserCertificateCollectionService);
  32. // ####
  33. UserCoursesCollectionService = new Backbone.Service({ url: path.root,
  34. sync: {
  35. 'read':{
  36. 'path':function () {
  37. return path.api.users
  38. + jQuery('#transcriptUserID').val()
  39. + '/courses';
  40. },
  41. 'method': 'get'
  42. }
  43. }
  44. });
  45. var UserCoursesCollection = Backbone.Collection.extend({
  46. model: TranscriptModel
  47. }).extend(UserCoursesCollectionService);
  48. // ####
  49. PackagesCollectionService = new Backbone.Service({ url: path.root,
  50. sync: {
  51. 'read': {
  52. 'path': path.api.gradebooks,
  53. 'data': function (e, options) {
  54. return {
  55. action: "GRADES",
  56. studyCourseId: options.courseId,
  57. courseId: Utils.getCourseId(),
  58. studentId: jQuery('#transcriptUserID').val(),
  59. page: "0",
  60. count: "1"
  61. }
  62. },
  63. 'method': 'get'
  64. }
  65. }
  66. });
  67. var PackagesCollection = Backbone.Collection.extend({
  68. model: TranscriptModel,
  69. parse: function (response) {
  70. this.trigger('packageCollection:updated', {totalGrade: response.gradeTotal});
  71. return response.packageGrades;
  72. }
  73. }).extend(PackagesCollectionService);
  74. CertificateGoalCollectionService = new Backbone.Service({ url: path.root,
  75. sync: {
  76. 'read': {
  77. 'path': function (e, options) {
  78. return path.api.certificates + options.certificateID;
  79. },
  80. 'data': function (e, options) {
  81. return {
  82. action: 'GETBYID',
  83. courseId: Utils.getCourseId()
  84. }
  85. },
  86. 'method': 'get'
  87. }
  88. }
  89. });
  90. var CertificateModel = Backbone.Model.extend({
  91. defaults: {
  92. }
  93. }).extend();
  94. var CertificateCollection = Backbone.Collection.extend({
  95. model: TranscriptModel,
  96. parse: function (response) {
  97. return response.records;
  98. }
  99. }).extend(UserCertificateCollectionService);
  100. var CertificateGoalCollection = Backbone.Collection.extend({
  101. model: CertificateModel,
  102. parse: function (response) {
  103. return response;
  104. }
  105. }).extend(CertificateGoalCollectionService);
  106. var StatementModel = Backbone.Model.extend({
  107. defaults: {}
  108. });
  109. var CertificateGoalStatusService = new Backbone.Service({ url: path.root,
  110. sync: {
  111. 'read': {
  112. path: function (e, options) {
  113. return path.api.users + jQuery('#transcriptUserID').val() + '/certificates/' + options.certificateID + '/goals';
  114. },
  115. 'method': 'get'
  116. }
  117. }
  118. });
  119. var CertificateGoalStatus = Backbone.Model.extend({
  120. defaults: {
  121. id: 0,
  122. isActivity: false,
  123. selected: false,
  124. value: "",
  125. title: "",
  126. validPeriod: ""
  127. }
  128. }).extend(CertificateGoalStatusService)
  129. // Pass amount=0 for filtered statements; amount=-1 for ALL statements
  130. StatementModelCollectionService = new Backbone.Service({ url: '/',
  131. sync: {
  132. 'read':{
  133. path: path.api.report,
  134. 'data': function (options) {
  135. return {
  136. action: "USER_LATEST_STATEMENTS",
  137. amount: options.amount
  138. }
  139. },
  140. 'method': 'get'
  141. }
  142. }
  143. });
  144. StatementModelCollection = Backbone.Collection.extend({
  145. model: StatementModel,
  146. parse: function (data) {
  147. // if (_.isObject(data.records)) {
  148. // this.trigger('update:statementCollection', {totalStatements: data.total, currentPage: data.page});
  149. return data.records;
  150. // } else {
  151. // return data;
  152. // }
  153. }
  154. }).extend(StatementModelCollectionService);
  155. PackageStatementCollection = Backbone.Collection.extend({
  156. model: StatementModel
  157. }).extend();
  158. /*UserModel = Backbone.Model.extend({
  159. defaults: {
  160. userID: '',
  161. name: '',
  162. selected: false
  163. }
  164. });*/
  165. UserService = new Backbone.Service({ url: path.root,
  166. sync: {
  167. 'read': function () {
  168. return path.api.users + '?userID=' + jQuery('#transcriptUserID').val();
  169. }
  170. }
  171. });
  172. var UserCollection = Backbone.Collection.extend({
  173. parse: function (data) {
  174. return data.records;
  175. }
  176. }).extend(UserService);
  177. PrintTranscriptService = new Backbone.Service({ url: '/',
  178. sync: {
  179. 'read' : function () {
  180. window.location = window.location.protocol + "//" +
  181. window.location.host + "/" +
  182. path.api.print + "?action=PRINT_TRANSCRIPT" +
  183. "&companyID=" + jQuery('#transcriptCompanyID').val() +
  184. "&userID=" + jQuery('#transcriptUserID').val() +
  185. "&courseId=" + Utils.getCourseId();
  186. }
  187. }
  188. });
  189. var PrintModel = Backbone.Model.extend({
  190. defaults: {}
  191. }).extend(PrintTranscriptService);