Advertisement
Guest User

Untitled

a guest
Apr 16th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 112.38 KB | None | 0 0
  1. (function (angular) {
  2.  
  3. "use strict";
  4.  
  5. var app = angular.module('ApLearningFrontend', ['ngRoute', 'ngLocale', 'ngSanitize', 'ui.bootstrap', 'angular-loading-bar']);
  6.  
  7. })(angular);
  8. (function (angular) {
  9.  
  10. "use strict";
  11.  
  12. var app = angular.module('ApLearningFrontend');
  13.  
  14. app.constant('eCompletionStatus', {
  15. NotStarted: 400,
  16. Started: 401,
  17. Completed: 402
  18. });
  19.  
  20. app.constant('eModuleType', {
  21. Text: 300,
  22. Test: 301,
  23. Survey: 302,
  24. Video: 303,
  25. Live: 304,
  26. Scorm: 305,
  27. GuidedNote: 306,
  28. GuidedNoteExport: 307
  29. });
  30.  
  31. app.constant('eTextCompletionMode', {
  32. AtOpening: 800,
  33. AtLastPage: 801
  34. });
  35.  
  36. app.constant('eNoteTarget', {
  37. Installation: 200,
  38. Course: 201,
  39. Module: 202
  40. });
  41.  
  42. app.constant('eTestRepeatMode', {
  43. Free: 2000,
  44. Limited: 2001,
  45. LimitedByDay: 2002
  46. });
  47.  
  48. app.constant('eVideoCompletionMode', {
  49. AtStart: 2200,
  50. AtEnd: 2201
  51. });
  52.  
  53. app.constant('eVideoTemplate', {
  54. BigVideo: 2300,
  55. BigText: 2301,
  56. BigSlides: 2302,
  57. AudioOnly: 2303
  58. });
  59.  
  60. app.constant('eSurveyQuestionType', {
  61. SingleChoice: 4000,
  62. MultipleChoice: 4001,
  63. FreeText: 4002
  64. });
  65.  
  66. app.constant('eSurveyDetailsMode', {
  67. NoDetail: 4500,
  68. DetailsAllowed: 4501,
  69. DetailsRequired: 4502
  70. });
  71.  
  72. app.constant('eGuidedNoteFieldType', {
  73. ShortText: 5000,
  74. LongText: 5001,
  75. Number: 5002
  76. });
  77.  
  78. })(angular);
  79. (function (angular, ApLearning, bootbox, Gauge) {
  80.  
  81. "use strict";
  82.  
  83. var app = angular.module('ApLearningFrontend');
  84.  
  85. app.service('bootbox', function () {
  86. return bootbox;
  87. });
  88.  
  89. app.service('Gauge', function () {
  90. return Gauge;
  91. });
  92.  
  93. app.service('ApLearning', function () {
  94. return ApLearning;
  95. });
  96.  
  97. app.service('Installation', ['$http', '$q', 'ApLearning', function ($http, $q, ApLearning) {
  98.  
  99. var installation = null;
  100.  
  101. function init() {
  102. var deferred = $q.defer();
  103.  
  104. if (installation) {
  105. deferred.resolve();
  106. } else {
  107.  
  108. $http({
  109. url: '/' + ApLearning.lang + '/App/GetInstallation',
  110. method: 'POST',
  111. responseType: 'json'
  112. }).success(function (data) {
  113. if (data.ok) {
  114. installation = data.result;
  115. deferred.resolve();
  116. } else {
  117. deferred.reject();
  118. }
  119. }).error(function () {
  120. deferred.reject();
  121. });
  122. }
  123.  
  124. return deferred.promise;
  125. }
  126.  
  127. return {
  128. init: init,
  129. getInstallation: function () {
  130. return installation;
  131. }
  132. }
  133.  
  134. }]);
  135.  
  136. app.service('SessionManager', ['$http', '$timeout', 'ApLearning', '$q', 'eCompletionStatus', function ($http, $timeout, ApLearning, $q, eCompletionStatus) {
  137.  
  138. var id = null, sessionID = null, courseID = null, unitID = null, moduleID = null, timer = null;
  139.  
  140. function startSession(courseid, unitid, moduleid) {
  141.  
  142. var deferred = $q.defer();
  143.  
  144. courseid = courseid || null;
  145. unitid = unitid || null;
  146. moduleid = moduleid || null;
  147.  
  148. if (id === null || courseid !== courseID || unitid !== unitID || moduleid !== moduleID) {
  149.  
  150. if (timer) {
  151. $timeout.cancel(timer);
  152. }
  153.  
  154. courseID = courseid;
  155. unitID = unitid;
  156. moduleID = moduleid;
  157.  
  158. id = null;
  159. sessionID = null;
  160.  
  161. $http({
  162. url: '/' + ApLearning.lang + '/App/StartSession',
  163. method: 'POST',
  164. data: {courseID: courseID, unitID: unitID, moduleID: moduleID},
  165. responseType: 'json'
  166. }).success(function (data) {
  167. if (data.ok) {
  168. id = data.id;
  169. sessionID = data.sessionID;
  170. timer = $timeout(ping, ApLearning.sessionTickSeconds * 1000);
  171. deferred.resolve({id: id, sessionID: sessionID});
  172. } else {
  173. deferred.reject(data.error);
  174. }
  175. }).error(function () {
  176. deferred.reject();
  177. });
  178. } else {
  179. deferred.resolve();
  180. }
  181.  
  182. return deferred.promise;
  183. }
  184.  
  185. function ping() {
  186. if (id && sessionID) {
  187. $http({
  188. url: '/' + ApLearning.lang + '/App/Ping',
  189. method: 'POST',
  190. data: {id: id, sessionID: sessionID},
  191. responseType: 'json'
  192. }).success(function () {
  193. timer = $timeout(ping, ApLearning.sessionTickSeconds * 1000);
  194. }).error(function () {
  195. timer = $timeout(ping, ApLearning.sessionTickSeconds * 1000);
  196. });
  197. }
  198. }
  199.  
  200. function setStarted(courseid, unitid, moduleid, status) {
  201. var deferred = $q.defer(),
  202. req = {
  203. SessionID: id,
  204. SessionCode: sessionID,
  205. CourseID: courseid,
  206. UnitID: unitid,
  207. ModuleID: moduleid,
  208. CompletionStatus: eCompletionStatus.Started,
  209. CustomStatus: status
  210. };
  211.  
  212. if (courseid == courseID && unitid == unitID && moduleid == moduleID) {
  213. $http({
  214. url: '/' + ApLearning.lang + '/App/SetStatus',
  215. method: 'POST',
  216. data: req,
  217. responseType: 'json'
  218. }).success(function (data) {
  219. if (data.ok) {
  220. deferred.resolve();
  221. } else {
  222. deferred.reject(data.error);
  223. }
  224. }).error(function () {
  225. deferred.reject();
  226. });
  227.  
  228. } else {
  229. deferred.reject("Session changed");
  230. }
  231.  
  232. return deferred.promise;
  233. }
  234.  
  235. function setCompleted(courseid, unitid, moduleid, status, pointsMin, pointsMax, pointsRaw) {
  236. var deferred = $q.defer(),
  237. req = {
  238. SessionID: id,
  239. SessionCode: sessionID,
  240. CourseID: courseid,
  241. UnitID: unitid,
  242. ModuleID: moduleid,
  243. CompletionStatus: eCompletionStatus.Completed,
  244. CustomStatus: status,
  245. PointsMin: pointsMin,
  246. PointsMax: pointsMax,
  247. PointsRaw: pointsRaw
  248. };
  249.  
  250. if (courseid == courseID && unitid == unitID && moduleid == moduleID) {
  251.  
  252. $http({
  253. url: '/' + ApLearning.lang + '/App/SetStatus',
  254. method: 'POST',
  255. data: req,
  256. responseType: 'json'
  257. }).success(function (data) {
  258. if (data.ok) {
  259. deferred.resolve();
  260. } else {
  261. deferred.reject(data.error);
  262. }
  263. }).error(function () {
  264. deferred.reject();
  265. });
  266. } else {
  267. deferred.reject("Session changed");
  268. }
  269.  
  270. return deferred.promise;
  271. }
  272.  
  273. function setCustomStatus(courseid, unitid, moduleid, status) {
  274. var deferred = $q.defer(),
  275. req = {
  276. SessionID: id,
  277. SessionCode: sessionID,
  278. CourseID: courseid,
  279. UnitID: unitid,
  280. ModuleID: moduleid,
  281. CustomStatus: status
  282. };
  283.  
  284. if (courseid == courseID && unitid == unitID && moduleid == moduleID) {
  285. $http({
  286. url: '/' + ApLearning.lang + '/App/SetCustomStatus',
  287. method: 'POST',
  288. data: req,
  289. responseType: 'json'
  290. }).success(function (data) {
  291. if (data.ok) {
  292. deferred.resolve();
  293. } else {
  294. deferred.reject(data.error);
  295. }
  296. }).error(function () {
  297. deferred.reject();
  298. });
  299. } else {
  300. deferred.reject("Session changed");
  301. }
  302.  
  303. return deferred.promise;
  304. }
  305.  
  306. function stopSession() {
  307. id = null;
  308. sessionID = null;
  309. }
  310.  
  311. function getSessionData() {
  312. return {
  313. id: id,
  314. sessionID: sessionID
  315. };
  316. }
  317.  
  318. return {
  319. startSession: startSession,
  320. setStarted: setStarted,
  321. setCompleted: setCompleted,
  322. setCustomStatus: setCustomStatus,
  323. stopSession: stopSession,
  324. getSessionData: getSessionData
  325. };
  326. }]);
  327.  
  328. app.service('Structure', ['$http', '$q', 'ApLearning', function ($http, $q, ApLearning) {
  329.  
  330. var structure = null, courses = {};
  331.  
  332. function init() {
  333. var deferred = $q.defer();
  334.  
  335. if (structure) {
  336. deferred.resolve();
  337. } else {
  338. $http({
  339. url: '/' + ApLearning.lang + '/App/GetCourses',
  340. method: 'POST',
  341. responseType: 'json'
  342. }).success(function (data) {
  343. var i, item, j, unit, k, module, previousModule = null;
  344. if (data.ok) {
  345. structure = data.courses;
  346. // Creo i dizionari per l'accesso diretto
  347. for (i in structure) {
  348. item = structure[i];
  349. courses[item.ID] = item;
  350. item.units = {};
  351. previousModule = null;
  352. for (j in item.Course.UnitsStatus) {
  353. unit = item.Course.UnitsStatus[j];
  354. item.units[unit.Unit.ID] = unit;
  355. unit.modules = {};
  356. for (k in unit.ModulesStatus) {
  357. module = unit.ModulesStatus[k];
  358. unit.modules[module.Module.ID] = module;
  359. if (previousModule) {
  360. previousModule.next = module;
  361. module.prev = previousModule;
  362. }
  363. previousModule = module;
  364. }
  365. }
  366. }
  367. deferred.resolve();
  368. } else {
  369. deferred.reject();
  370. }
  371. }).error(function () {
  372. deferred.reject();
  373. });
  374. }
  375.  
  376. return deferred.promise;
  377. }
  378.  
  379. return {
  380. init: init,
  381. getStructure: function () {
  382. return structure;
  383. },
  384. getCourse: function (courseId) {
  385. return courses[courseId];
  386. },
  387. getUnit: function (courseId, unitId) {
  388. return courses[courseId].units[unitId];
  389. },
  390. getModule: function (courseId, unitId, moduleId) {
  391. return courses[courseId].units[unitId].modules[moduleId];
  392. },
  393. reload: function () {
  394. structure = null;
  395. courses = {};
  396. return init();
  397. }
  398. }
  399. }]);
  400.  
  401. app.service('UserNotes', ['$http', '$q', 'ApLearning', 'eNoteTarget', function ($http, $q, ApLearning, eNoteTarget) {
  402.  
  403. var notes = null;
  404.  
  405. function loadNotes() {
  406. var deferred = $q.defer();
  407.  
  408. if (notes != null) {
  409. deferred.resolve(notes);
  410. } else {
  411. $http({
  412. url: '/' + ApLearning.lang + '/App/GetNotes',
  413. method: 'GET',
  414. responseType: 'json'
  415. }).success(function (data) {
  416. if (data.ok) {
  417. notes = data.notes;
  418. deferred.resolve(notes);
  419. } else {
  420. deferred.reject(data.error);
  421. }
  422. }).error(function () {
  423. deferred.reject('Network error');
  424. });
  425. }
  426.  
  427. return deferred.promise;
  428. }
  429.  
  430. return {
  431. getAllNotes: function () {
  432. var deferred = $q.defer();
  433.  
  434. loadNotes().then(function (data) {
  435. deferred.resolve(data);
  436. }, function (error) {
  437. deferred.reject(error);
  438. });
  439.  
  440. return deferred.promise;
  441. },
  442. getNotes: function (courseID, moduleID) {
  443. var deferred = $q.defer();
  444.  
  445. loadNotes().then(function () {
  446. var res = [], i, item;
  447.  
  448. for (i in notes) {
  449. item = notes[i];
  450. if (!courseID && !moduleID && item.Note.Target == eNoteTarget.Installation) {
  451. res.push(item);
  452. continue;
  453. }
  454. if (moduleID && item.Note.Target == eNoteTarget.Module && item.Note.TargetEntityID == moduleID) {
  455. res.push(item);
  456. continue;
  457. }
  458.  
  459. if (courseID && item.Note.Target == eNoteTarget.Course && item.Note.TargetEntityID == courseID) {
  460. res.push(item);
  461. }
  462. }
  463.  
  464. deferred.resolve(res);
  465. }, function (error) {
  466. deferred.reject(error);
  467. });
  468.  
  469. return deferred.promise;
  470. },
  471. reload: function () {
  472. notes = null;
  473. return loadNotes();
  474. }
  475. }
  476. }]);
  477.  
  478. })(angular, ApLearning, bootbox, Gauge);
  479. (function (angular) {
  480.  
  481. "use strict";
  482.  
  483. var app = angular.module('ApLearningFrontend');
  484.  
  485. app.config(['$routeProvider', function ($routeProvider) {
  486. $routeProvider
  487. .when('/dashboard', {
  488. templateUrl: '/App/Views/dashboard/dashboard.html',
  489. controller: 'DashboardController'
  490. })
  491. .when('/calendar', {
  492. templateUrl: '/App/Views/calendar.html',
  493. controller: 'CalendarEventsController'
  494. })
  495. .when('/statistics', {
  496. templateUrl: '/App/Views/statistics/statistics.html',
  497. controller: 'StatisticsController'
  498. })
  499. .when('/course/:courseId/:unitId?', {
  500. templateUrl: '/App/Views/course/course.html',
  501. controller: 'CourseController'
  502. })
  503. .when('/teachers/:courseId', {
  504. templateUrl: '/App/Views/course/teachers.html',
  505. controller: 'CourseController'
  506. })
  507. .when('/library/:courseId', {
  508. templateUrl: '/App/Views/course/library.html',
  509. controller: 'CourseController'
  510. })
  511. .when('/completed/:courseId', {
  512. templateUrl: '/App/Views/course/completed.html',
  513. controller: 'CourseController'
  514. })
  515. .when('/forums/:courseId', {
  516. templateUrl: '/App/Views/course/forum/forums.html',
  517. controller: 'CourseController'
  518. })
  519. .when('/module/:courseId/:unitId/:moduleId', {
  520. templateUrl: '/App/Views/module/module.html',
  521. controller: 'ModuleController'
  522. })
  523. .otherwise({
  524. redirectTo: '/dashboard'
  525. });
  526. }]);
  527.  
  528. })(angular);
  529. (function (angular) {
  530.  
  531. "use strict";
  532.  
  533. var app = angular.module('ApLearningFrontend');
  534.  
  535. app.controller('HeaderController', ['$scope', 'ApLearning', 'Installation', 'Labels', '$location', '$window', '$rootScope',
  536. function ($scope, ApLearning, Installation, Labels, $location, $window, $rootScope) {
  537. $scope.ApLearning = ApLearning;
  538. $scope.Installation = null;
  539. $scope.Labels = Labels;
  540. $scope.helpVisible = false;
  541. $scope.notesVisible = false;
  542. $scope.section = 'dashboard';
  543.  
  544. $scope.toggleHelp = function () {
  545. $scope.helpVisible = !$scope.helpVisible;
  546. if ($scope.helpVisible) {
  547. $rootScope.$broadcast('popupOpen', 'help');
  548. }
  549. };
  550.  
  551. $scope.toggleNotes = function () {
  552. $scope.notesVisible = !$scope.notesVisible;
  553. if ($scope.notesVisible) {
  554. $rootScope.$broadcast('popupOpen', 'notes');
  555. }
  556. };
  557.  
  558. $scope.goToHome = function () {
  559. $location.path('/dashboard');
  560. };
  561.  
  562. $scope.goToCalendar = function () {
  563. $location.path('/calendar');
  564. };
  565.  
  566. $scope.goToStatistics = function () {
  567. $location.path('/statistics');
  568. };
  569.  
  570. $scope.toggleLang = function () {
  571. $window.location.href = ApLearning.lang == 'it' ? '/en/App#' + $location.path() : '/it/App#' + $location.path();
  572. };
  573.  
  574. Installation.init().then(function () {
  575. $scope.Installation = Installation.getInstallation();
  576. });
  577.  
  578. function parseLocation() {
  579. var parts = $location.path().split('/');
  580. if (parts.length > 1) {
  581. $scope.section = parts[1];
  582. } else {
  583. $scope.section = "dashboard";
  584. }
  585. }
  586.  
  587. $scope.$on("$routeChangeSuccess", function () {
  588. parseLocation();
  589. $scope.helpVisible = false;
  590. $scope.notesVisible = false;
  591. });
  592.  
  593. $scope.$on("popupOpen", function (e, popup) {
  594. if (popup != 'help') {
  595. $scope.helpVisible = false;
  596. }
  597. if (popup != 'notes') {
  598. $scope.notesVisible = false;
  599. }
  600. });
  601. }]);
  602.  
  603. app.controller('HelpTopicController', ['$scope', function ($scope) {
  604. $scope.topicVisible = false;
  605. $scope.toggleTopicVisible = function () {
  606. $scope.topicVisible = !$scope.topicVisible;
  607. }
  608. }]);
  609.  
  610. app.controller('CalendarEventsController', ['$scope', '$http', 'ApLearning', 'bootbox', 'Labels',
  611. function ($scope, $http, ApLearning, bootbox, Labels) {
  612.  
  613. var now = new Date(), year = now.getFullYear(), month = now.getMonth() + 1;
  614.  
  615. $scope.Labels = Labels;
  616.  
  617. $scope.date = null;
  618. $scope.calendar = null;
  619. $scope.events = null;
  620.  
  621. $scope.next = function () {
  622. month++;
  623. if (month > 12) {
  624. month = 1;
  625. year++;
  626. }
  627. loadCalendar();
  628. };
  629.  
  630. $scope.prev = function () {
  631. month--;
  632. if (month < 1) {
  633. month = 12;
  634. year--;
  635. }
  636. loadCalendar();
  637. };
  638.  
  639. function loadCalendar() {
  640. $http({
  641. url: '/' + ApLearning.lang + '/App/GetMonthEvents/' + year + '-' + month,
  642. method: 'GET',
  643. responseType: 'json'
  644. }).success(function (data) {
  645. if (data.ok) {
  646. $scope.date = data.events.date;
  647. $scope.calendar = data.events.calendar;
  648. $scope.events = data.events.events;
  649. } else {
  650. bootbox.alert('Error: ' + data.error);
  651. }
  652. }).error(function () {
  653. bootbox.alert('Network error');
  654. });
  655. }
  656.  
  657. loadCalendar();
  658.  
  659. $("body").css("background-image", "url('" + ApLearning.defaultBackgroundUrl + "')");
  660. }]);
  661.  
  662. app.controller('CalendarItemController', ['$scope', function ($scope) {
  663. $scope.detailVisible = false;
  664. $scope.toggleDetail = function () {
  665. $scope.detailVisible = !$scope.detailVisible;
  666. };
  667. }]);
  668.  
  669. app.controller('NotesListController', ['$scope', 'Labels', 'UserNotes', '$http', 'ApLearning', 'bootbox', '$rootScope', '$window',
  670. function ($scope, Labels, UserNotes, $http, ApLearning, bootbox, $rootScope, $window) {
  671. var pageSize = 10;
  672.  
  673. $scope.notes = null;
  674. $scope.page = 0;
  675. $scope.pages = 1;
  676. $scope.pageNotes = null;
  677. $scope.currentNote = null;
  678.  
  679. $scope.next = function () {
  680. $scope.page++;
  681. setupPage();
  682. };
  683.  
  684. $scope.prev = function () {
  685. $scope.page--;
  686. setupPage();
  687. };
  688.  
  689. $scope.selectAll = function () {
  690. var i, item, select = false;
  691. for (i in $scope.pageNotes) {
  692. item = $scope.pageNotes[i];
  693. if (!item.Selected) {
  694. select = true;
  695. break;
  696. }
  697. }
  698. for (i in $scope.pageNotes) {
  699. item = $scope.pageNotes[i];
  700. item.Selected = select;
  701. }
  702. };
  703.  
  704. $scope.deleteMulti = function () {
  705. var ids = [];
  706. $scope.pageNotes.forEach(function (item) {
  707. if (item.Selected) {
  708. ids.push(item.ID);
  709. }
  710. });
  711.  
  712. if (ids.length) {
  713. bootbox.confirm(Labels.confirmDeleteNotes, function (confirm) {
  714. if (confirm) {
  715. $http({
  716. url: '/' + ApLearning.lang + '/App/DeleteNoteMulti/' + ids.join('-'),
  717. method: 'POST',
  718. responseType: 'json'
  719. }).success(function (data) {
  720. if (data.ok) {
  721. UserNotes.reload().then(function () {
  722. $rootScope.$broadcast('NotesChanged');
  723. });
  724. } else {
  725. bootbox.alert('Error: ' + data.error);
  726. }
  727. }).error(function () {
  728. bootbox.alert('Network error');
  729. });
  730. }
  731. });
  732. } else {
  733. bootbox.alert(Labels.chooseNotes);
  734. }
  735. };
  736.  
  737. $scope.exportMulti = function () {
  738. var ids = [], url;
  739. $scope.pageNotes.forEach(function (item) {
  740. if (item.Selected) {
  741. ids.push(item.ID);
  742. }
  743. });
  744.  
  745. if (ids.length) {
  746. url = '/' + ApLearning.lang + '/App/ExportMulti/' + ids.join('-');
  747. $window.location.href = url;
  748. } else {
  749. bootbox.alert(Labels.chooseNotes);
  750. }
  751. };
  752.  
  753. $scope.backToListing = function () {
  754. $scope.currentNote = null;
  755. };
  756.  
  757. $scope.exportSingle = function () {
  758. $scope.pageNotes.forEach(function (item) {
  759. item.Selected = item.ID == $scope.currentNote.ID;
  760. });
  761.  
  762. $scope.exportMulti();
  763. };
  764.  
  765. $scope.deleteSingle = function () {
  766. bootbox.confirm(Labels.confirmDeleteNote, function (confirm) {
  767. if (confirm) {
  768. $http({
  769. url: '/' + ApLearning.lang + '/App/DeleteNoteMulti/' + $scope.currentNote.ID,
  770. method: 'POST',
  771. responseType: 'json'
  772. }).success(function (data) {
  773. if (data.ok) {
  774. UserNotes.reload().then(function () {
  775. $rootScope.$broadcast('NotesChanged');
  776. $scope.backToListing();
  777. });
  778. } else {
  779. bootbox.alert('Error: ' + data.error);
  780. }
  781. }).error(function () {
  782. bootbox.alert('Network error');
  783. });
  784. }
  785. });
  786. };
  787.  
  788. $scope.open = function (note) {
  789. $scope.currentNote = note;
  790. };
  791.  
  792. $scope.save = function (frm) {
  793. if (frm.$valid) {
  794. $http({
  795. url: '/' + ApLearning.lang + '/App/SaveNote',
  796. method: 'POST',
  797. data: JSON.stringify($scope.currentNote.Note),
  798. headers: {
  799. 'Content-Type': "application/json"
  800. }
  801. }).success(function (data) {
  802. if (data.ok) {
  803. UserNotes.reload().then(function () {
  804. $rootScope.$broadcast('NotesChanged');
  805. //bootbox.alert(Labels.noteSaved);
  806. frm.$setPristine();
  807. });
  808. } else {
  809. bootbox.alert('Error: ' + data.error);
  810. }
  811. }).error(function () {
  812. bootbox.alert('Network error');
  813. });
  814. }
  815. };
  816.  
  817. $scope.$on('NotesChanged', loadNotes);
  818.  
  819. function setupPage() {
  820. var mod = $scope.notes.length % pageSize,
  821. pages = ($scope.notes.length - mod) / pageSize;
  822.  
  823. $scope.notes.forEach(function (item) {
  824. item.Selected = false;
  825. });
  826. $scope.pages = pages + (mod ? 1 : 0);
  827. $scope.pageNotes = $scope.notes.slice($scope.page * pageSize, ($scope.page + 1) * pageSize);
  828. }
  829.  
  830. function loadNotes() {
  831. UserNotes.getAllNotes().then(function (notes) {
  832. $scope.notes = notes;
  833. setupPage();
  834. });
  835. }
  836.  
  837. loadNotes();
  838. }]);
  839.  
  840. app.controller('NotesWidgetController', ['$scope', 'Labels', '$routeParams', 'UserNotes', '$http', 'eNoteTarget', 'ApLearning', 'bootbox', '$rootScope',
  841. function ($scope, Labels, $routeParams, UserNotes, $http, eNoteTarget, ApLearning, bootbox, $rootScope) {
  842.  
  843. $scope.Labels = Labels;
  844. $scope.visible = false;
  845. $scope.notes = null;
  846. $scope.currentNoteID = null;
  847. $scope.currentNote = null;
  848.  
  849. $scope.toggle = function () {
  850. $scope.visible = !$scope.visible;
  851. if ($scope.visible) {
  852. $rootScope.$broadcast('popupOpen', 'notesWidget');
  853. }
  854. };
  855.  
  856. $scope.goToNote = function (noteID) {
  857. if (noteID >= 0 && $scope.notes && $scope.notes.length > noteID) {
  858. $scope.currentNote = $scope.notes[noteID].Note;
  859. $scope.currentNoteID = noteID;
  860. } else {
  861. $scope.currentNote = {ID: 0, Date: new Date()};
  862. $scope.currentNoteID = -1;
  863. }
  864. };
  865.  
  866. $scope.saveNote = function (frm) {
  867.  
  868. if (frm.$valid) {
  869.  
  870. if (!$scope.currentNote.ID) {
  871. if ($routeParams.moduleId) {
  872. $scope.currentNote.Target = eNoteTarget.Module;
  873. $scope.currentNote.TargetEntityID = $routeParams.moduleId;
  874. } else if ($routeParams.courseId) {
  875. $scope.currentNote.Target = eNoteTarget.Course;
  876. $scope.currentNote.TargetEntityID = $routeParams.courseId;
  877. } else {
  878. $scope.currentNote.Target = eNoteTarget.Installation;
  879. $scope.currentNote.TargetEntityID = null;
  880. }
  881. }
  882.  
  883. $http({
  884. url: '/' + ApLearning.lang + '/App/SaveNote',
  885. method: 'POST',
  886. data: JSON.stringify($scope.currentNote),
  887. headers: {
  888. 'Content-Type': "application/json"
  889. }
  890. }).success(function (data) {
  891. if (data.ok) {
  892. UserNotes.reload().then(function () {
  893. $rootScope.$broadcast('NotesChanged');
  894. frm.$setPristine();
  895. });
  896. } else {
  897. bootbox.alert('Error: ' + data.error);
  898. }
  899. }).error(function () {
  900. bootbox.alert('Network error');
  901. });
  902. }
  903. };
  904.  
  905. $scope.deleteNote = function () {
  906. if ($scope.currentNote && $scope.currentNote.ID) {
  907. bootbox.confirm(Labels.confirmDeleteNote, function (confirm) {
  908. if (confirm) {
  909. $http({
  910. url: '/' + ApLearning.lang + '/App/DeleteNote/' + $scope.currentNote.ID,
  911. method: 'POST',
  912. responseType: 'json'
  913. }).success(function (data) {
  914. if (data.ok) {
  915. UserNotes.reload().then(function () {
  916. $rootScope.$broadcast('NotesChanged');
  917. });
  918. } else {
  919. bootbox.alert('Error: ' + data.error);
  920. }
  921. }).error(function () {
  922. bootbox.alert('Network error');
  923. })
  924. }
  925. });
  926. }
  927. };
  928.  
  929. $scope.goBack = function () {
  930. if ($scope.currentNoteID == -1) {
  931. $scope.goToNote($scope.notes.length - 1);
  932. } else {
  933. if ($scope.currentNoteID > 0) {
  934. $scope.goToNote($scope.currentNoteID - 1);
  935. }
  936. }
  937. };
  938.  
  939. $scope.goNext = function () {
  940. if ($scope.currentNoteID < ($scope.notes.length - 1)) {
  941. $scope.goToNote($scope.currentNoteID + 1);
  942. }
  943. };
  944.  
  945. $scope.$on('NotesChanged', loadNotes);
  946.  
  947. function loadNotes() {
  948. $scope.visible = false;
  949. UserNotes.getNotes($routeParams.courseId, $routeParams.moduleId).then(function (notes) {
  950. $scope.notes = notes;
  951. if ($scope.notes.length) {
  952. $scope.goToNote($scope.notes.length - 1);
  953. } else {
  954. $scope.goToNote(-1);
  955. }
  956. });
  957. }
  958.  
  959. loadNotes();
  960.  
  961. $scope.$on('$routeChangeSuccess', loadNotes);
  962.  
  963. $scope.$on("popupOpen", function (e, popup) {
  964. if (popup != 'notesWidget') {
  965. $scope.visible = false;
  966. }
  967. });
  968. }]);
  969.  
  970. })(angular);
  971. (function (angular) {
  972.  
  973. "use strict";
  974.  
  975. var app = angular.module('ApLearningFrontend');
  976.  
  977. app.directive('header', function () {
  978. return {
  979. restrict: 'E',
  980. templateUrl: '/App/Views/header.html',
  981. controller: 'HeaderController'
  982. }
  983. });
  984.  
  985. app.directive('gauge', ['Gauge', function () {
  986.  
  987. var link = function ($scope, jelement, attrs) {
  988. var canvas = jelement.find('canvas');
  989.  
  990. var size = jelement.parent().width();
  991.  
  992. canvas.attr('height', size + 'px').attr('width', size + 'px');
  993.  
  994. $scope.gauge = new Gauge(canvas[0], {
  995. color: "#FFF",
  996. bgcolor: "rgba(255,255,255,0.5)",
  997. font: "30px Helvetica"
  998. });
  999. $scope.gauge.value($scope.value || 0);
  1000.  
  1001. $scope.$watch('value', function () {
  1002. $scope.gauge.value($scope.value || 0);
  1003. })
  1004. };
  1005.  
  1006. return {
  1007. restrict: 'E',
  1008. link: link,
  1009. scope: {value: '='},
  1010. template: '<canvas />'
  1011. }
  1012. }]);
  1013.  
  1014. app.directive('noteslist', function () {
  1015. return {
  1016. restrict: 'E',
  1017. templateUrl: '/App/Views/notes.html',
  1018. controller: 'NotesListController'
  1019. }
  1020. });
  1021.  
  1022. app.directive('note', function () {
  1023. return {
  1024. restrict: 'E',
  1025. templateUrl: '/App/Views/notes_widget.html',
  1026. controller: 'NotesWidgetController'
  1027. }
  1028. });
  1029.  
  1030. app.directive('resizedimage', function () {
  1031.  
  1032. function link($scope, element, attrs) {
  1033. $scope.width = attrs.width;
  1034. $scope.height = attrs.height;
  1035. $scope.title = attrs.title || '';
  1036. }
  1037.  
  1038. return {
  1039. restrict: 'E',
  1040. template: '<img ng-src="{{ url }}" title="{{ title }}" alt="{{ title }}" />',
  1041. replace: true,
  1042. link: link,
  1043. scope: {
  1044. imageurl: '='
  1045. },
  1046. controller: ['$scope', function ($scope) {
  1047. function loadImage() {
  1048. $scope.url = '/img/Resize/' + $scope.width + 'x' + $scope.height + $scope.imageurl;
  1049. }
  1050.  
  1051. $scope.$watch('imageurl', loadImage)
  1052. }]
  1053. };
  1054. });
  1055.  
  1056. app.directive('fittedimage', function () {
  1057.  
  1058. function link($scope, element, attrs) {
  1059. $scope.width = attrs.width;
  1060. $scope.height = attrs.height;
  1061. $scope.title = attrs.title || '';
  1062. }
  1063.  
  1064. return {
  1065. restrict: 'E',
  1066. template: '<img ng-src="{{ url }}" title="{{ title }}" alt="{{ title }}" />',
  1067. replace: true,
  1068. link: link,
  1069. scope: {
  1070. imageurl: '='
  1071. },
  1072. controller: ['$scope', function ($scope) {
  1073. function loadImage() {
  1074. $scope.url = '/img/Fit/' + $scope.width + 'x' + $scope.height + $scope.imageurl;
  1075. }
  1076.  
  1077. $scope.$watch('imageurl', loadImage)
  1078. }]
  1079. };
  1080.  
  1081. });
  1082.  
  1083. })(angular);
  1084. (function (angular) {
  1085.  
  1086. "use strict";
  1087.  
  1088. var app = angular.module('ApLearningFrontend');
  1089.  
  1090. app.controller('DashboardController', ['$scope', '$http', 'ApLearning', 'Installation', 'SessionManager', 'Structure', 'Labels', 'bootbox', 'eCompletionStatus', '$location',
  1091. function ($scope, $http, ApLearning, Installation, SessionManager, Structure, Labels, bootbox, eCompletionStatus, $location) {
  1092.  
  1093. $scope.Labels = Labels;
  1094. $scope.eCompletionStatus = eCompletionStatus;
  1095.  
  1096. $scope.courses = null;
  1097. $scope.Installation = null;
  1098.  
  1099. $scope.goToCourse = function (id) {
  1100. $location.path('/course/' + id);
  1101. };
  1102.  
  1103. Installation.init().then(function () {
  1104. $scope.Installation = Installation.getInstallation();
  1105. });
  1106.  
  1107. SessionManager.startSession();
  1108.  
  1109. Structure.init().then(function () {
  1110. $scope.courses = Structure.getStructure();
  1111. $("body").css("background-image", "url('" + ApLearning.defaultBackgroundUrl + "')");
  1112. });
  1113. }]);
  1114.  
  1115.  
  1116. })(angular);
  1117. (function (angular) {
  1118.  
  1119. "use strict";
  1120.  
  1121. var app = angular.module('ApLearningFrontend');
  1122.  
  1123. app.controller('CourseController', ['$scope', '$routeParams', '$location', 'Structure', 'SessionManager', 'Labels',
  1124. function ($scope, $routeParams, $location, Structure, SessionManager, Labels) {
  1125.  
  1126. $scope.courseId = Number($routeParams.courseId);
  1127. $scope.unitId = $routeParams.unitId ? Number($routeParams.unitId) : null;
  1128. $scope.Labels = Labels;
  1129. $scope.section = "course";
  1130.  
  1131. $scope.goToDashboard = function () {
  1132. $location.path('/dashboard');
  1133. };
  1134.  
  1135. $scope.goToCourse = function () {
  1136. $location.path('/course/' + $scope.courseId);
  1137. };
  1138.  
  1139. $scope.goToCompleted = function () {
  1140. $location.path('/completed/' + $scope.courseId);
  1141. };
  1142.  
  1143. $scope.goToModule = function (unitId, module) {
  1144. if (module.CanAccess) {
  1145. $location.path('/module/' + $scope.courseId + '/' + unitId + '/' + module.Module.ID);
  1146. }
  1147. };
  1148.  
  1149. $scope.goToTeachers = function () {
  1150. $location.path('/teachers/' + $scope.courseId);
  1151. };
  1152.  
  1153. $scope.goToLibrary = function () {
  1154. $location.path('/library/' + $scope.courseId);
  1155. };
  1156.  
  1157. $scope.goToForums = function () {
  1158.  
  1159. var url = '/forums/' + $scope.courseId;
  1160.  
  1161. if ($location.path() == url) {
  1162. document.location.reload();
  1163. }
  1164. else {
  1165. $location.path(url);
  1166. }
  1167.  
  1168. };
  1169.  
  1170. $scope.course = null;
  1171.  
  1172. Structure.init().then(function () {
  1173. var i;
  1174. $scope.course = Structure.getCourse($scope.courseId);
  1175. if ($scope.course.Course.UnitsStatus.length === 1) {
  1176. for (i in $scope.course.units) {
  1177. $scope.course.units[i].showContent = true;
  1178. break;
  1179. }
  1180. }
  1181. if ($scope.course.CustomBackgroundUrl) {
  1182. $("body").css("background-image", "url('" + $scope.course.CustomBackgroundUrl + "')");
  1183. }
  1184. });
  1185.  
  1186. SessionManager.startSession($scope.courseId);
  1187.  
  1188. function parseLocation() {
  1189. var parts = $location.path().split('/');
  1190. if (parts.length > 1) {
  1191. $scope.section = parts[1];
  1192. } else {
  1193. $scope.section = "dashboard";
  1194. }
  1195. }
  1196.  
  1197. $scope.$on("$routeChangeSuccess", function () {
  1198. parseLocation();
  1199. });
  1200. }]);
  1201.  
  1202. app.controller('TeacherBoxController', ['$scope', '$http', 'bootbox', 'ApLearning', function ($scope, $http, bootbox, ApLearning) {
  1203. $scope.request = {Text: null};
  1204. $scope.contactBoxOpen = false;
  1205. $scope.formSubmitted = false;
  1206. $scope.messageSent = false;
  1207.  
  1208. $scope.toggleContactBox = function () {
  1209. $scope.contactBoxOpen = !$scope.contactBoxOpen
  1210. };
  1211.  
  1212. $scope.send = function (frm) {
  1213. var req;
  1214. $scope.formSubmitted = true;
  1215. console.log(frm);
  1216. if (frm.$valid) {
  1217. req = {
  1218. CourseID: $scope.courseId,
  1219. TeacherID: $scope.teacher.ID,
  1220. MessageText: $scope.request.Text
  1221. };
  1222. $http({
  1223. url: '/' + ApLearning.lang + '/App/SendMessageToTeacher',
  1224. method: 'POST',
  1225. data: JSON.stringify(req),
  1226. headers: {
  1227. 'Content-Type': "application/json"
  1228. }
  1229. }).success(function (data) {
  1230. if (data.ok) {
  1231. $scope.messageSent = true;
  1232. } else {
  1233. bootbox.alert('Error: ' + data.error);
  1234. }
  1235. }).error(function () {
  1236. bootbox.alert('Network error');
  1237. })
  1238. }
  1239. };
  1240. }]);
  1241.  
  1242. app.controller('ForumsController', ['$scope', '$routeParams', '$http', 'ApLearning', 'Labels', 'bootbox', '$q',
  1243. function ($scope, $routeParams, $http, ApLearning, Labels, bootbox, $q) {
  1244.  
  1245. $scope.courseId = Number($routeParams.courseId);
  1246. $scope.Labels = Labels;
  1247. $scope.forums = null;
  1248.  
  1249. $scope.currentForum = null;
  1250. $scope.threads = null;
  1251. $scope.newThreadSubmitted = false;
  1252. $scope.newThread = null;
  1253. $scope.threadsPaging = {
  1254. currentPage: 1,
  1255. pageSize: 10,
  1256. threadsCount: null,
  1257. pager: []
  1258. };
  1259.  
  1260. $scope.currentThread = null;
  1261. $scope.posts = null;
  1262. $scope.newPostSubmitted = false;
  1263. $scope.postsPaging = {
  1264. currentPage: 1,
  1265. pageSize: 10,
  1266. postsCount: null,
  1267. pager: []
  1268. };
  1269.  
  1270. $scope.currentPost = null;
  1271.  
  1272. $scope.goToCourse = function () {
  1273. $location.path('/course/' + $scope.courseId);
  1274. };
  1275.  
  1276. $scope.goToList = function () {
  1277. $scope.currentPost = null;
  1278. $scope.posts = null;
  1279. $scope.currentThread = null;
  1280. $scope.threads = null;
  1281. $scope.currentForum = null;
  1282. };
  1283.  
  1284. $scope.goToThreads = function () {
  1285. $scope.currentPost = null;
  1286. $scope.posts = null;
  1287. $scope.currentThread = null;
  1288. };
  1289.  
  1290. $scope.goToForum = function () {
  1291. $scope.currentThread = null;
  1292. };
  1293.  
  1294.  
  1295. $scope.openForum = function (forum) {
  1296. $scope.currentForum = forum;
  1297. $scope.threadsPaging.currentPage = 1;
  1298. return loadThreads();
  1299. };
  1300.  
  1301. $scope.showNewThread = function () {
  1302. $scope.newThreadSubmitted = false;
  1303. $scope.newThread = {
  1304. ID: 0,
  1305. ForumID: $scope.currentForum.ID
  1306. };
  1307. };
  1308. $scope.hideNewThread = function () {
  1309. $scope.newThreadSubmitted = false;
  1310. $scope.newThread = null;
  1311. };
  1312.  
  1313. $scope.createNewThread = function (frm) {
  1314. var req = {
  1315. courseID: $scope.courseId,
  1316. forumID: $scope.currentForum.ID,
  1317. thread: $scope.newThread,
  1318. text: $scope.newThread.Text
  1319. };
  1320. $scope.newThreadSubmitted = true;
  1321. if (frm.$valid) {
  1322. $http({
  1323. url: '/' + ApLearning.lang + '/App/CreateThread',
  1324. method: 'POST',
  1325. data: JSON.stringify(req),
  1326. responseType: 'json',
  1327. headers: {
  1328. 'Content-Type': "application/json"
  1329. }
  1330. }).success(function (data) {
  1331. if (data.ok) {
  1332. $scope.newThread = null;
  1333. $scope.newThreadSubmitted = false;
  1334. $scope.postsPaging.currentPage = 1;
  1335. $scope.threadsPaging.currentPage = 1;
  1336. loadForums().then(function () {
  1337. var i, item;
  1338. // Recupero il precedente forum corrente
  1339. for (i in $scope.forums) {
  1340. item = $scope.forums[i];
  1341. if (item.ID == $scope.currentForum.ID) {
  1342. $scope.openForum(item).then(function () {
  1343. $scope.currentThread = data.entity;
  1344. loadPosts();
  1345. });
  1346. break;
  1347. }
  1348. }
  1349.  
  1350. });
  1351. } else {
  1352. bootbox.alert('Error: ' + data.error);
  1353. }
  1354. }).error(function () {
  1355. bootbox.alert('Network error.');
  1356. });
  1357. }
  1358. };
  1359.  
  1360. $scope.goToThreadPage = function (pageNr) {
  1361. $scope.threadsPaging.currentPage = pageNr;
  1362. loadThreads();
  1363. };
  1364.  
  1365. $scope.nextThreadPage = function () {
  1366. $scope.threadsPaging.currentPage++;
  1367. loadThreads();
  1368. };
  1369.  
  1370. $scope.prevThreadPage = function () {
  1371. $scope.threadsPaging.currentPage--;
  1372. loadThreads();
  1373. };
  1374.  
  1375. $scope.goToPostPage = function (pageNr) {
  1376. $scope.postsPaging.currentPage = pageNr;
  1377. loadPosts();
  1378. };
  1379.  
  1380. $scope.nextPostPage = function () {
  1381. $scope.postsPaging.currentPage++;
  1382. loadPosts();
  1383. };
  1384.  
  1385. $scope.prevPostPage = function () {
  1386. $scope.postsPaging.currentPage--;
  1387. loadPosts();
  1388. };
  1389.  
  1390. $scope.openThread = function (thread) {
  1391. $scope.currentThread = thread;
  1392. $scope.postsPaging.currentPage = 1;
  1393. $scope.currentPost = null;
  1394. loadPosts();
  1395. };
  1396.  
  1397. $scope.showPostReply = function (post) {
  1398. var reRx = /^[\s]*re:/i;
  1399. post = post ? angular.copy(post) : {
  1400. ThreadID: $scope.currentThread.ID,
  1401. Title: $scope.currentThread.Thread.Title
  1402. };
  1403.  
  1404. post.ID = 0;
  1405.  
  1406. if (!reRx.test(post.Title)) {
  1407. post.Title = 'Re: ' + post.Title;
  1408. }
  1409.  
  1410. if (post.Text) {
  1411. post.Text = '[quote]' + post.Text + '[/quote]';
  1412. }
  1413.  
  1414. $scope.currentPost = post;
  1415. $scope.newPostSubmitted = post.ID > 0;
  1416. };
  1417.  
  1418. $scope.editPost = function (post) {
  1419. $scope.newPostSubmitted = true;
  1420. $scope.currentPost = angular.copy(post);
  1421. };
  1422.  
  1423. $scope.savePost = function (frm) {
  1424. var req, isNew;
  1425. $scope.newPostSubmitted = true;
  1426. if (frm.$valid) {
  1427. isNew = $scope.currentPost.ID == 0;
  1428. req = {
  1429. courseID: $scope.courseId,
  1430. forumID: $scope.currentForum.ID,
  1431. threadID: $scope.currentThread.ID,
  1432. pageSize: $scope.postsPaging.pageSize,
  1433. post: $scope.currentPost
  1434. };
  1435. $http({
  1436. url: '/' + ApLearning.lang + '/App/SavePost',
  1437. method: 'POST',
  1438. data: JSON.stringify(req),
  1439. responseType: 'json',
  1440. headers: {
  1441. 'Content-Type': "application/json"
  1442. }
  1443. }).success(function (data) {
  1444. if (data.ok) {
  1445. $scope.postsPaging.currentPage = data.pageNr;
  1446. loadForums().then(function () {
  1447. loadThreads().then(function () {
  1448. loadPosts();
  1449. $scope.currentPost = null;
  1450. $scope.newPostSubmitted = false;
  1451. });
  1452. })
  1453. } else {
  1454. bootbox.alert('Error: ' + data.error);
  1455. }
  1456. }).error(function () {
  1457. bootbox.alert("Network error");
  1458. });
  1459. }
  1460. };
  1461.  
  1462. $scope.deleteCurrentPost = function () {
  1463. bootbox.confirm(Labels.confirmPostDeletion, function (confirm) {
  1464. if (confirm) {
  1465. $http({
  1466. url: '/' + ApLearning.lang + '/App/DeletePost/' + $scope.courseId + '-' + $scope.currentForum.ID + '-' + $scope.currentThread.ID + '-' + $scope.currentPost.ID,
  1467. method: 'POST',
  1468. responseType: 'json'
  1469. }).success(function (data) {
  1470. if (data.ok) {
  1471. $scope.currentPost = null;
  1472. loadForums().then(function () {
  1473. loadThreads().then(function () {
  1474. loadPosts();
  1475. });
  1476. });
  1477. } else {
  1478. bootbox.alert('Error: ' + data.error);
  1479. }
  1480. }).error(function () {
  1481. bootbox.alert('Network error')
  1482. });
  1483. }
  1484. });
  1485. };
  1486.  
  1487. $scope.deleteCurrentThread = function () {
  1488. bootbox.confirm(Labels.confirmThreadDeletion, function (confirm) {
  1489. if (confirm) {
  1490. $http({
  1491. url: '/' + ApLearning.lang + '/App/DeleteThread/' + $scope.courseId + '-' + $scope.currentForum.ID + '-' + $scope.currentThread.ID,
  1492. method: 'POST',
  1493. responseType: 'json'
  1494. }).success(function (data) {
  1495. if (data.ok) {
  1496. $scope.currentPost = null;
  1497. loadForums().then(function () {
  1498. loadThreads().then(function () {
  1499. $scope.goToThreads();
  1500. });
  1501. });
  1502. } else {
  1503. bootbox.alert('Error: ' + data.error);
  1504. }
  1505. }).error(function () {
  1506. bootbox.alert('Network error')
  1507. });
  1508. }
  1509. });
  1510. };
  1511.  
  1512. $scope.lockCurrentThread = function () {
  1513. bootbox.confirm(Labels.confirmThreadLocking, function (confirm) {
  1514. if (confirm) {
  1515. $http({
  1516. url: '/' + ApLearning.lang + '/App/LockThread/' + $scope.courseId + '-' + $scope.currentForum.ID + '-' + $scope.currentThread.ID,
  1517. method: 'POST',
  1518. responseType: 'json'
  1519. }).success(function (data) {
  1520. if (data.ok) {
  1521. $scope.currentPost = null;
  1522. loadForums().then(function () {
  1523. loadThreads().then(function () {
  1524. var i, item;
  1525. for (i in $scope.threads) {
  1526. item = $scope.threads[i];
  1527. if (item.ID == $scope.currentThread.ID) {
  1528. $scope.currentThread = item;
  1529. break;
  1530. }
  1531. }
  1532. loadPosts();
  1533. });
  1534. });
  1535. } else {
  1536. bootbox.alert('Error: ' + data.error);
  1537. }
  1538. }).error(function () {
  1539. bootbox.alert('Network error')
  1540. });
  1541. }
  1542. });
  1543. };
  1544.  
  1545. $scope.unlockCurrentThread = function () {
  1546. bootbox.confirm(Labels.confirmThreadUnlocking, function (confirm) {
  1547. if (confirm) {
  1548. $http({
  1549. url: '/' + ApLearning.lang + '/App/UnlockThread/' + $scope.courseId + '-' + $scope.currentForum.ID + '-' + $scope.currentThread.ID,
  1550. method: 'POST',
  1551. responseType: 'json'
  1552. }).success(function (data) {
  1553. if (data.ok) {
  1554. $scope.currentPost = null;
  1555. loadForums().then(function () {
  1556. loadThreads().then(function () {
  1557. var i, item;
  1558. for (i in $scope.threads) {
  1559. item = $scope.threads[i];
  1560. if (item.ID == $scope.currentThread.ID) {
  1561. $scope.currentThread = item;
  1562. break;
  1563. }
  1564. }
  1565. loadPosts();
  1566. });
  1567. });
  1568. } else {
  1569. bootbox.alert('Error: ' + data.error);
  1570. }
  1571. }).error(function () {
  1572. bootbox.alert('Network error')
  1573. });
  1574. }
  1575. });
  1576. };
  1577.  
  1578. $scope.closePostEdit = function () {
  1579. $scope.currentPost = null;
  1580. };
  1581.  
  1582. function loadForums() {
  1583. var deferred = $q.defer();
  1584. $http({
  1585. url: '/' + ApLearning.lang + '/App/GetForumsList/' + $scope.courseId,
  1586. method: 'GET',
  1587. responseType: 'json'
  1588. }).success(function (data) {
  1589. if (data.ok) {
  1590. $scope.forums = data.result;
  1591. deferred.resolve();
  1592. } else {
  1593. bootbox.alert("Error: " + data.error);
  1594. deferred.reject();
  1595. }
  1596. }).error(function () {
  1597. bootbox.alert('Network Error.');
  1598. deferred.reject();
  1599. });
  1600.  
  1601. return deferred.promise;
  1602. }
  1603.  
  1604. function loadThreads() {
  1605. var deferred = $q.defer();
  1606. $http({
  1607. url: '/' + ApLearning.lang + '/App/GetThreadsList',
  1608. method: 'POST',
  1609. data: {
  1610. courseID: $scope.courseId,
  1611. forumID: $scope.currentForum.ID,
  1612. pageNr: $scope.threadsPaging.currentPage,
  1613. pageSize: $scope.threadsPaging.pageSize
  1614. },
  1615. responseType: 'json'
  1616. }).success(function (data) {
  1617. var i;
  1618. if (data.ok) {
  1619. $scope.threads = data.result.Threads;
  1620. $scope.threadsPaging.threadsCount = data.result.Count;
  1621. $scope.threadsPaging.pager = [];
  1622. for (i = 1; i <= data.result.Pages; i++) {
  1623. $scope.threadsPaging.pager.push({
  1624. page: i,
  1625. isCurrent: i == $scope.threadsPaging.currentPage
  1626. });
  1627. }
  1628. deferred.resolve();
  1629. } else {
  1630. bootbox.alert('Error: ' + data.error)
  1631. deferred.reject();
  1632. }
  1633. }).error(function () {
  1634. bootbox.alert('Network error.');
  1635. deferred.reject();
  1636. });
  1637.  
  1638. return deferred.promise;
  1639. }
  1640.  
  1641. function loadPosts() {
  1642. var deferred = $q.defer();
  1643. $http({
  1644. url: '/' + ApLearning.lang + '/App/GetPostsList',
  1645. method: 'POST',
  1646. data: {
  1647. courseID: $scope.courseId,
  1648. forumID: $scope.currentForum.ID,
  1649. threadID: $scope.currentThread.ID,
  1650. pageNr: $scope.postsPaging.currentPage,
  1651. pageSize: $scope.postsPaging.pageSize
  1652. },
  1653. responseType: 'json'
  1654. }).success(function (data) {
  1655. var i;
  1656. if (data.ok) {
  1657. $scope.posts = data.result.Posts;
  1658. $scope.postsPaging.postsCount = data.result.Count;
  1659. $scope.postsPaging.pager = [];
  1660. for (i = 1; i <= data.result.Pages; i++) {
  1661. $scope.postsPaging.pager.push({
  1662. page: i,
  1663. isCurrent: i == $scope.postsPaging.currentPage
  1664. });
  1665. }
  1666. deferred.resolve();
  1667. } else {
  1668. bootbox.alert('Error: ' + data.error);
  1669. deferred.reject();
  1670. }
  1671. }).error(function () {
  1672. bootbox.alert('Network error.');
  1673. deferred.reject();
  1674. });
  1675.  
  1676. return deferred.promise;
  1677. }
  1678.  
  1679. loadForums();
  1680. }]);
  1681.  
  1682. })(angular);
  1683. (function (angular) {
  1684.  
  1685. "use strict";
  1686.  
  1687. var app = angular.module('ApLearningFrontend');
  1688.  
  1689. app.controller('ModuleController', ['$scope', '$routeParams', '$location', 'Labels', 'eModuleType', 'Structure',
  1690. function ($scope, $routeParams, $location, Labels, eModuleType, Structure) {
  1691.  
  1692. var courseId = Number($routeParams.courseId), unitId = Number($routeParams.unitId), moduleId = Number($routeParams.moduleId);
  1693.  
  1694. $scope.Labels = Labels;
  1695. $scope.course = null;
  1696. $scope.unit = null;
  1697. $scope.module = null;
  1698. $scope.moduleTemplateUrl = '/App/Views/module/loading.html';
  1699.  
  1700. $scope.goToCourse = function () {
  1701. $location.path('/course/' + courseId + '/' + unitId);
  1702. };
  1703.  
  1704. $scope.goToNextModule = function () {
  1705. if ($scope.module.next) {
  1706. $location.path('/module/' + courseId + '/' + $scope.module.next.Module.UnitID + '/' + $scope.module.next.Module.ID);
  1707. }
  1708. };
  1709.  
  1710. $scope.goToPrevModule = function () {
  1711. if ($scope.module.prev) {
  1712. $location.path('/module/' + courseId + '/' + $scope.module.prev.Module.UnitID + '/' + $scope.module.prev.Module.ID);
  1713. }
  1714. };
  1715.  
  1716. $scope.statusChanged = function () {
  1717. Structure.reload().then(function () {
  1718. $scope.course = Structure.getCourse(courseId);
  1719. $scope.unit = Structure.getUnit(courseId, unitId);
  1720. $scope.module = Structure.getModule(courseId, unitId, moduleId);
  1721. })
  1722. };
  1723.  
  1724. $scope.goToTeachers = function () {
  1725. $location.path('/teachers/' + courseId);
  1726. };
  1727.  
  1728. $scope.goToLibrary = function () {
  1729. $location.path('/library/' + courseId);
  1730. };
  1731.  
  1732. $scope.goToCompleted = function () {
  1733. $location.path('/completed/' + courseId);
  1734. };
  1735.  
  1736. $scope.goToForums = function () {
  1737. $location.path('/forums/' + courseId);
  1738. };
  1739.  
  1740. Structure.init().then(function () {
  1741. $scope.course = Structure.getCourse(courseId);
  1742. $scope.unit = Structure.getUnit(courseId, unitId);
  1743. $scope.module = Structure.getModule(courseId, unitId, moduleId);
  1744.  
  1745. if (!$scope.module.CanAccess) {
  1746. $scope.moduleTemplateUrl = '/App/Views/module/unauthorized.html';
  1747. } else {
  1748.  
  1749. switch ($scope.module.Module.ModuleType) {
  1750. case eModuleType.Text:
  1751. $scope.moduleTemplateUrl = "/App/Views/module/text/text.html";
  1752. break;
  1753. case eModuleType.Test:
  1754. $scope.moduleTemplateUrl = "/App/Views/module/test/test.html";
  1755. break;
  1756. case eModuleType.Video:
  1757. $scope.moduleTemplateUrl = "/App/Views/module/video/video.html";
  1758. break;
  1759. case eModuleType.Scorm:
  1760. $scope.moduleTemplateUrl = "/App/Views/module/scorm/scormlesson.html";
  1761. break;
  1762. case eModuleType.Survey:
  1763. $scope.moduleTemplateUrl = "/App/Views/module/survey/survey.html";
  1764. break;
  1765. case eModuleType.GuidedNote:
  1766. $scope.moduleTemplateUrl = "/App/Views/module/guidednote/guidednote.html";
  1767. break;
  1768. case eModuleType.GuidedNoteExport:
  1769. $scope.moduleTemplateUrl = "/App/Views/module/guidednoteexport/guidednoteexport.html";
  1770. break;
  1771. }
  1772. }
  1773. });
  1774.  
  1775. }]);
  1776.  
  1777. })(angular);
  1778. (function (angular) {
  1779.  
  1780. "use strict";
  1781.  
  1782. var app = angular.module('ApLearningFrontend');
  1783.  
  1784. app.controller('StatisticsController', ['$scope', '$http', 'ApLearning', 'bootbox', 'SessionManager', function ($scope, $http, ApLearning, bootbox, SessionManager) {
  1785.  
  1786. $scope.courses = null;
  1787.  
  1788. function loadCurses() {
  1789. $http({
  1790. url: '/' + ApLearning.lang + '/CourseStats/GetCoursesWithStatistics',
  1791. method: 'POST',
  1792. responseType: 'json'
  1793. }).success(function (data) {
  1794. if (data.ok) {
  1795. $scope.courses = data.courses;
  1796. } else {
  1797. bootbox.alert('Error: ' + data.error);
  1798. }
  1799. }).error(function () {
  1800. bootbox.alert('Network error');
  1801. });
  1802. }
  1803.  
  1804. loadCurses();
  1805. $("body").css("background-image", "url('" + ApLearning.defaultBackgroundUrl + "')");
  1806.  
  1807. SessionManager.startSession();
  1808. }]);
  1809.  
  1810. app.controller('CourseStatisticsController', ['$scope', '$http', 'ApLearning', 'Labels', '$window', 'cfpLoadingBar', "$modal",
  1811. function ($scope, $http, ApLearning, Labels, $window, cfpLoadingBar, $modal) {
  1812.  
  1813. $scope.detailsVisible = false;
  1814. $scope.unitStatistics = null;
  1815. $scope.courseStatistics = null;
  1816. $scope.Labels = Labels;
  1817.  
  1818. function loadStatistics() {
  1819.  
  1820. $http
  1821. .post('/' + ApLearning.lang + '/CourseStats/GetCourseStatistics/' + $scope.course.ID, null)
  1822. .then(function (resp) {
  1823. if (resp.data.ok) {
  1824. $scope.unitStatistics = resp.data.result;
  1825. $scope.courseStatistics = resp.data.courseStats;
  1826. } else {
  1827. bootbox.alert('Error: ' + data.error);
  1828. }
  1829. });
  1830. }
  1831.  
  1832. $scope.exportDetails = function () {
  1833. $window.location.href = '/' + ApLearning.lang + '/CourseStats/GetCourseStatisticsExport/' + $scope.course.ID;
  1834. };
  1835.  
  1836. $scope.sendDetails = function () {
  1837.  
  1838. var modalInstance = $modal.open({
  1839. templateUrl: '/App/Views/statistics/send/template.html',
  1840. controller: 'CourseStatisticsSendController',
  1841. size: 'md',
  1842. scope: $scope
  1843. });
  1844.  
  1845. };
  1846.  
  1847. $scope.toggleDetails = function () {
  1848. $scope.detailsVisible = !$scope.detailsVisible;
  1849. if ($scope.detailsVisible) {
  1850. loadStatistics();
  1851. }
  1852. }
  1853. }]);
  1854.  
  1855. })(angular);
  1856. (function (angular) {
  1857. "use strict";
  1858. var app = angular.module('ApLearningFrontend');
  1859.  
  1860. app.controller('CourseStatisticsSendController', ['$scope', '$http', 'ApLearning', 'Labels', "$modalInstance",
  1861. function ($scope, $http, ApLearning, Labels, $modalInstance) {
  1862.  
  1863. $scope.states = {
  1864. submitted: false,
  1865. posting: false
  1866. };
  1867.  
  1868. $scope.data = {
  1869. courseID: $scope.course.ID,
  1870. recipient: "",
  1871. title: Labels.statSendSubjectDefault,
  1872. message: Labels.statSendMessageDefault
  1873. };
  1874.  
  1875. $scope.send = function (form) {
  1876. $scope.states.submitted = true;
  1877.  
  1878. if (!form.$valid) {
  1879. return;
  1880. }
  1881.  
  1882. $scope.states.posting = true;
  1883.  
  1884. $http
  1885. .post('/' + ApLearning.lang + '/CourseStats/SendCourseStatisticsExport/', $scope.data)
  1886. .then(function (resp) {
  1887.  
  1888. $scope.states.posting = false;
  1889.  
  1890. if (resp.data.ok) {
  1891. bootbox.alert("Report inviato");
  1892. } else {
  1893. bootbox.alert('Error: ' + data.error);
  1894. }
  1895.  
  1896. $modalInstance.close();
  1897. });
  1898. };
  1899.  
  1900. $scope.cancel = function () {
  1901. $modalInstance.close();
  1902. };
  1903.  
  1904. }]);
  1905.  
  1906. })(angular);
  1907. (function (angular) {
  1908.  
  1909. "use strict";
  1910.  
  1911. var app = angular.module('ApLearningFrontend');
  1912.  
  1913. app.controller('TextModuleController', ['$scope', '$http', 'ApLearning', 'bootbox', 'SessionManager', 'eTextCompletionMode', 'eCompletionStatus',
  1914. function ($scope, $http, ApLearning, bootbox, SessionManager, eTextCompletionMode, eCompletionStatus) {
  1915.  
  1916. $scope.completionMode = null;
  1917. $scope.completionStatus = eCompletionStatus.NotStarted;
  1918. $scope.pages = null;
  1919. $scope.status = {currentPageID: 0};
  1920. $scope.show = false;
  1921. $scope.currentPage = null;
  1922.  
  1923. $scope.nextPage = function () {
  1924. if ($scope.status.currentPageID < ($scope.pages.length - 1)) {
  1925. $scope.status.currentPageID++;
  1926. $scope.currentPage = $scope.pages[$scope.status.currentPageID];
  1927.  
  1928. if ($scope.status.currentPageID == ($scope.pages.length - 1) && $scope.completionMode == eTextCompletionMode.AtLastPage && $scope.completionStatus != eCompletionStatus.Completed) {
  1929. SessionManager.setCompleted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID, JSON.stringify($scope.status))
  1930. .then(function () {
  1931. $scope.statusChanged();
  1932. $scope.completionStatus = eCompletionStatus.Completed;
  1933. },
  1934. function (error) {
  1935. bootbox.alert("Error completing session: " + error);
  1936. });
  1937. } else {
  1938. storeCurrentPage();
  1939. }
  1940. }
  1941. };
  1942.  
  1943. $scope.prevPage = function () {
  1944. if ($scope.status.currentPageID > 0) {
  1945. $scope.status.currentPageID--;
  1946. $scope.currentPage = $scope.pages[$scope.status.currentPageID];
  1947. storeCurrentPage();
  1948. }
  1949. };
  1950.  
  1951. function storeCurrentPage() {
  1952. SessionManager.setCustomStatus($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID, JSON.stringify($scope.status));
  1953. }
  1954.  
  1955. function goToStoredPage() {
  1956. if ($scope.pages && $scope.status.currentPageID < $scope.pages.length) {
  1957. $scope.currentPage = $scope.pages[$scope.status.currentPageID];
  1958. }
  1959. }
  1960.  
  1961. function loadConfig() {
  1962. $http({
  1963. url: '/' + ApLearning.lang + '/Module/GetTextModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  1964. method: 'GET',
  1965. responseType: 'json'
  1966. }).success(function (data) {
  1967. if (data.ok) {
  1968. $scope.completionMode = data.config.CompletionMode;
  1969. $scope.completionStatus = data.config.CompletionStatus;
  1970. $scope.pages = data.config.Pages;
  1971. $scope.status = data.config.Status ? JSON.parse(data.config.Status) : $scope.status;
  1972.  
  1973. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  1974. .then(function () {
  1975.  
  1976. if ($scope.completionStatus != eCompletionStatus.Completed && ($scope.completionMode == eTextCompletionMode.AtOpening || $scope.pages.length === 1)) {
  1977. SessionManager.setCompleted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID, JSON.stringify($scope.status))
  1978. .then(function () {
  1979. $scope.show = true;
  1980. $scope.statusChanged();
  1981. $scope.completionStatus = eCompletionStatus.Completed;
  1982. goToStoredPage();
  1983. },
  1984. function (error) {
  1985. bootbox.alert("Error starting session: " + error);
  1986. });
  1987. } else {
  1988. if ($scope.completionStatus == eCompletionStatus.NotStarted) {
  1989. SessionManager.setStarted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID, JSON.stringify($scope.status))
  1990. .then(function () {
  1991. $scope.show = true;
  1992. $scope.statusChanged();
  1993. $scope.eCompletionStatus = eCompletionStatus.Started;
  1994. goToStoredPage();
  1995. }, function (error) {
  1996. bootbox.alert("Error starting session: " + error);
  1997. });
  1998. } else {
  1999. $scope.show = true;
  2000. goToStoredPage();
  2001. }
  2002. }
  2003.  
  2004. }, function (error) {
  2005. bootbox.alert("Error starting session: " + error);
  2006. });
  2007.  
  2008. } else {
  2009. bootbox.alert('Error: ' + data.error);
  2010. }
  2011. }).error(function () {
  2012. bootbox.alert('Network error');
  2013. });
  2014. }
  2015.  
  2016. loadConfig();
  2017.  
  2018. }]);
  2019.  
  2020. })(angular);
  2021. (function (angular) {
  2022.  
  2023. "use strict";
  2024.  
  2025. var app = angular.module('ApLearningFrontend');
  2026.  
  2027. app.controller('TestModuleController', ['$scope', '$http', 'ApLearning', 'eTestRepeatMode', 'Labels', 'SessionManager', 'bootbox', '$timeout',
  2028. function ($scope, $http, ApLearning, eTestRepeatMode, Labels, SessionManager, bootbox, $timeout) {
  2029. var startTime = null;
  2030.  
  2031. $scope.Labels = Labels;
  2032. $scope.eTestRepeatMode = eTestRepeatMode;
  2033. $scope.eStep = {
  2034. INTRO: 1,
  2035. QUESTIONS: 2,
  2036. RESULTS: 3,
  2037. TIMEOUT: 4
  2038. };
  2039.  
  2040. // aggiunte mdg
  2041. $scope.introView = "default"; // default|completed
  2042. $scope.canRepeat = false;
  2043. // fine aggiunte mdg
  2044.  
  2045. $scope.instructions = null;
  2046. $scope.limitTimeMinutes = null;
  2047. $scope.allowShowAnswers = null;
  2048. $scope.completionStatus = null;
  2049. $scope.repeatMode = null;
  2050. $scope.repeatsLeft = 0;
  2051. $scope.currentSession = null;
  2052.  
  2053. $scope.questions = null;
  2054. $scope.currentQuestionID = null;
  2055. $scope.currentQuestion = null;
  2056. $scope.hasAllAnswers = false;
  2057.  
  2058. $scope.remainingTime = "";
  2059.  
  2060. $scope.result = null;
  2061. $scope.success = false;
  2062. $scope.correctAnswers = null;
  2063.  
  2064. $scope.currentStep = $scope.eStep.INTRO;
  2065.  
  2066. function reset() {
  2067. $scope.instructions = null;
  2068. $scope.limitTimeMinutes = null;
  2069. $scope.completionStatus = null;
  2070. $scope.repeatMode = null;
  2071. $scope.repeatsLeft = 0;
  2072. $scope.currentSession = null;
  2073. $scope.questions = null;
  2074. $scope.currentQuestionID = null;
  2075. $scope.currentQuestion = null;
  2076. $scope.hasAllAnswers = false;
  2077. $scope.result = null;
  2078. $scope.success = false;
  2079. }
  2080.  
  2081. function timerTick() {
  2082. var now = new Date(), diffSeconds = parseInt("" + (now - startTime) / 1000),
  2083. remainingSeconds = (60 * $scope.limitTimeMinutes) - diffSeconds,
  2084. seconds = remainingSeconds % 60, minutes = (remainingSeconds - seconds) / 60;
  2085.  
  2086. if (remainingSeconds < 0 && $scope.currentStep == $scope.eStep.QUESTIONS) {
  2087. $scope.currentStep = $scope.eStep.TIMEOUT;
  2088. SessionManager.stopSession();
  2089. reset();
  2090. return;
  2091. }
  2092.  
  2093. $scope.remainingTime = minutes + ':' + (seconds < 10 ? '0' + seconds : seconds);
  2094. if ($scope.currentStep == $scope.eStep.QUESTIONS) {
  2095. $timeout(timerTick, 200);
  2096. }
  2097. }
  2098.  
  2099. $scope.startTest = function () {
  2100. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID).then(function (sessionCreated) {
  2101. var req = {
  2102. courseID: $scope.course.ID,
  2103. unitID: $scope.unit.Unit.ID,
  2104. moduleID: $scope.module.Module.ID,
  2105. sessionID: sessionCreated.id,
  2106. sessionCode: sessionCreated.sessionID
  2107. };
  2108. $scope.currentSession = sessionCreated;
  2109. $http({
  2110. url: '/' + ApLearning.lang + '/Module/StartTest',
  2111. method: 'POST',
  2112. data: JSON.stringify(req),
  2113. responseType: 'json', headers: {
  2114. 'Content-Type': "application/json"
  2115. }
  2116. }).success(function (data) {
  2117. if (data.ok) {
  2118. startTime = new Date();
  2119. $scope.statusChanged();
  2120. $scope.questions = data.questions;
  2121. $scope.currentQuestionID = 0;
  2122. $scope.currentQuestion = $scope.questions[$scope.currentQuestionID];
  2123. $scope.currentStep = $scope.eStep.QUESTIONS;
  2124. $scope.hasAllAnswers = false;
  2125. if ($scope.limitTimeMinutes) {
  2126. timerTick();
  2127. }
  2128. } else {
  2129. bootbox.alert('Error: ' + data.error);
  2130. }
  2131. }).error(function () {
  2132. bootbox.alert('Network error');
  2133. })
  2134.  
  2135. }, function (error) {
  2136. bootbox.alert('Error: ' + error);
  2137. })
  2138. };
  2139.  
  2140. $scope.prevQuestion = function () {
  2141. if ($scope.currentQuestionID === 0) {
  2142. return;
  2143. }
  2144. $scope.currentQuestionID--;
  2145. $scope.currentQuestion = $scope.questions[$scope.currentQuestionID];
  2146. };
  2147.  
  2148. $scope.nextQuestion = function () {
  2149. if ($scope.currentQuestionID === ($scope.questions.length - 1)) {
  2150. return;
  2151. }
  2152. $scope.currentQuestionID++;
  2153. $scope.currentQuestion = $scope.questions[$scope.currentQuestionID];
  2154. };
  2155.  
  2156. $scope.checkAllAnswers = function () {
  2157. var i, item;
  2158.  
  2159. for (i in $scope.questions) {
  2160. item = $scope.questions[i];
  2161. if (!item.AnswerID) {
  2162. $scope.hasAllAnswers = false;
  2163. return;
  2164. }
  2165. }
  2166. $scope.hasAllAnswers = true;
  2167. };
  2168.  
  2169. $scope.evaluate = function () {
  2170. var answers = [], i, item,
  2171. req = {
  2172. courseID: $scope.course.ID,
  2173. unitID: $scope.unit.Unit.ID,
  2174. moduleID: $scope.module.Module.ID,
  2175. sessionID: $scope.currentSession.id,
  2176. sessionCode: $scope.currentSession.sessionID,
  2177. answers: answers
  2178. };
  2179. for (i in $scope.questions) {
  2180. item = $scope.questions[i];
  2181. if (item.AnswerID) {
  2182. answers.push(item.AnswerID);
  2183. }
  2184. }
  2185. $http({
  2186. url: '/' + ApLearning.lang + '/Module/EvaluateTest',
  2187. method: 'POST',
  2188. data: JSON.stringify(req),
  2189. responseType: 'json', headers: {
  2190. 'Content-Type': "application/json"
  2191. }
  2192. }).success(function (data) {
  2193. if (data.ok) {
  2194. SessionManager.stopSession();
  2195. reset();
  2196. $scope.result = data.result;
  2197. $scope.success = data.success;
  2198. $scope.currentStep = $scope.eStep.RESULTS;
  2199. $scope.statusChanged();
  2200. } else {
  2201. bootbox.alert('Error: ' + data.error);
  2202. }
  2203. }).error(function () {
  2204. bootbox.alert('Network error');
  2205. })
  2206. };
  2207.  
  2208. $scope.showCorrectAnswers = function () {
  2209.  
  2210. if ($scope.canRepeat) {
  2211. bootbox.confirm(Labels.showCorrectAnswersConfirm, function (confirm) {
  2212. if (confirm) {
  2213. showCorrectAnswers();
  2214. }
  2215. });
  2216. }
  2217. else {
  2218. showCorrectAnswers();
  2219. }
  2220.  
  2221. };
  2222.  
  2223. function showCorrectAnswers() {
  2224. var req = {
  2225. courseID: $scope.course.ID,
  2226. unitID: $scope.unit.Unit.ID,
  2227. moduleID: $scope.module.Module.ID
  2228. };
  2229. $http({
  2230. url: '/' + ApLearning.lang + '/Module/GetTestAnswers',
  2231. method: 'POST',
  2232. data: JSON.stringify(req),
  2233. responseType: 'json',
  2234. headers: {
  2235. 'Content-Type': "application/json"
  2236. }
  2237. }).success(function (data) {
  2238. if (data.ok) {
  2239. $scope.correctAnswers = data.answers;
  2240.  
  2241. // aggiunta mdg
  2242. $scope.canRepeat = false;
  2243. // fine aggiunta mdg
  2244.  
  2245. } else {
  2246. bootbox.alert('Error: ' + data.error);
  2247. }
  2248. }).error(function () {
  2249. bootbox.alert('Network error');
  2250. })
  2251. }
  2252.  
  2253. $scope.goToStart = function () {
  2254. $scope.allowShowAnswers = null;
  2255. $scope.currentStep = $scope.eStep.INTRO;
  2256. loadConfig();
  2257. };
  2258.  
  2259. function loadConfig() {
  2260. $http({
  2261. url: '/' + ApLearning.lang + '/Module/GetTestModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2262. method: 'GET',
  2263. responseType: 'json'
  2264. }).success(function (data) {
  2265. if (data.ok) {
  2266.  
  2267. $scope.instructions = data.config.Instructions;
  2268. $scope.limitTimeMinutes = data.config.LimitTimeSeconds;
  2269. $scope.completionStatus = data.config.CompletionStatus;
  2270. $scope.repeatMode = data.config.RepeatMode;
  2271. $scope.repeatsLeft = data.config.RepeatsLeft;
  2272. $scope.allowShowAnswers = data.config.AllowShowAnswers;
  2273.  
  2274. // aggiunta mdg
  2275. $scope.canRepeat = $scope.repeatsLeft > 0;
  2276. if ($scope.completionStatus == 402) {
  2277. $scope.introView = "completed";
  2278. }
  2279. // fine aggiunta mdg
  2280.  
  2281.  
  2282. } else {
  2283. bootbox.alert('Error: ' + data.error);
  2284. }
  2285. }).error(function () {
  2286. bootbox.alert('Network error');
  2287. });
  2288. }
  2289.  
  2290. loadConfig();
  2291.  
  2292. }]);
  2293.  
  2294. })(angular);
  2295. (function (angular) {
  2296.  
  2297. "use strict";
  2298.  
  2299. var app = angular.module('ApLearningFrontend');
  2300.  
  2301. app.controller('VideoModuleController', ['$scope', '$http', 'eVideoTemplate', 'bootbox', 'SessionManager', 'eVideoCompletionMode',
  2302. function ($scope, $http, eVideoTemplate, bootbox, SessionManager, eVideoCompletionMode) {
  2303.  
  2304. $scope.templateUrl = null;
  2305. $scope.videoUrl = null;
  2306. $scope.videoStreamType = null;
  2307. $scope.completionMode = null;
  2308. $scope.slides = null;
  2309. $scope.useTimeline = false;
  2310. $scope.currentSlide = null;
  2311. $scope.currentSlideID = null;
  2312. $scope.title = null;
  2313. $scope.abstract = null;
  2314. $scope.videoPosition = {position: 0, duration: 0};
  2315.  
  2316. $scope.videoStarted = function () {
  2317. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2318. .then(function () {
  2319. if ($scope.completionMode == eVideoCompletionMode.AtStart) {
  2320. SessionManager.setCompleted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2321. .then(function () {
  2322. $scope.statusChanged();
  2323. },
  2324. function (error) {
  2325. bootbox.alert("Error starting session: " + error);
  2326. });
  2327. } else {
  2328. SessionManager.setStarted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2329. .then(function () {
  2330. $scope.statusChanged();
  2331. }, function (error) {
  2332. bootbox.alert("Error starting session: " + error);
  2333. });
  2334. }
  2335. }, function (error) {
  2336. bootbox.alert("Error starting session: " + error);
  2337. })
  2338. };
  2339.  
  2340. $scope.videoCompleted = function () {
  2341. SessionManager.setCompleted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2342. .then(function () {
  2343. $scope.statusChanged();
  2344. },
  2345. function (error) {
  2346. bootbox.alert("Error starting session: " + error);
  2347. });
  2348. };
  2349.  
  2350. $scope.videoStopped = function () {
  2351. SessionManager.stopSession();
  2352. };
  2353.  
  2354. $scope.previousSlide = function () {
  2355. $scope.loadSlide($scope.currentSlideID - 1);
  2356. };
  2357.  
  2358. $scope.nextSlide = function () {
  2359. $scope.loadSlide($scope.currentSlideID + 1);
  2360. };
  2361.  
  2362. $scope.loadSlide = function (slideID) {
  2363. $scope.currentSlideID = slideID;
  2364. $scope.currentSlide = $scope.slides[slideID];
  2365. };
  2366.  
  2367. $scope.checkSlide = function () {
  2368. var i, item;
  2369. if ($scope.useTimeline) {
  2370. for (i = $scope.slides.length - 1; i >= 0; i--) {
  2371. item = $scope.slides[i];
  2372. if ($scope.videoPosition.position >= item.TimelineSeconds) {
  2373. if ($scope.currentSlideID != i) {
  2374. $scope.loadSlide(i);
  2375. }
  2376. break;
  2377. }
  2378. }
  2379. }
  2380. };
  2381.  
  2382. function loadConfig() {
  2383. $http({
  2384. url: '/' + ApLearning.lang + '/Module/GetVideoModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2385. method: 'GET',
  2386. responseType: 'json'
  2387. }).success(function (data) {
  2388. if (data.ok) {
  2389.  
  2390. if (data.config.UrlType == "full") {
  2391. $scope.videoUrl = data.config.File;
  2392. }
  2393. else {
  2394. $scope.videoUrl = ApLearning.videoStreamingEndpoint + '/' + data.config.File;
  2395. }
  2396. console.log("video url: " + $scope.videoUrl);
  2397.  
  2398. $scope.videoStreamType = data.config.StreamType;
  2399. $scope.completionMode = data.config.CompletionMode;
  2400. $scope.title = data.config.Title;
  2401. $scope.abstract = data.config.Abstract;
  2402. $scope.useTimeline = data.config.UseTimeline;
  2403. $scope.slides = data.config.Slides;
  2404. if ($scope.slides.length > 0) {
  2405. $scope.loadSlide(0);
  2406. }
  2407.  
  2408. switch (data.config.Template) {
  2409. case eVideoTemplate.BigVideo:
  2410. $scope.templateUrl = '/App/Views/module/video/tpl_bigvideo.html';
  2411. break;
  2412. case eVideoTemplate.BigText:
  2413. $scope.templateUrl = '/App/Views/module/video/tpl_bigtext.html';
  2414. break;
  2415. case eVideoTemplate.BigSlides:
  2416. $scope.templateUrl = '/App/Views/module/video/tpl_bigslides.html';
  2417. break;
  2418. case eVideoTemplate.AudioOnly:
  2419. $scope.templateUrl = '/App/Views/module/video/tpl_audioonly.html';
  2420. break;
  2421. }
  2422.  
  2423. } else {
  2424. bootbox.alert('Error: ' + data.error);
  2425. }
  2426. }).error(function () {
  2427. bootbox.alert('Network error');
  2428. });
  2429. }
  2430.  
  2431. loadConfig();
  2432. }]);
  2433.  
  2434. app.directive('videoplayer', ['ApLearning', 'eVideoCompletionMode', '$timeout', function (ApLearning, eVideoCompletionMode, $timeout) {
  2435.  
  2436. function link($scope, element, attrs) {
  2437.  
  2438.  
  2439. $scope.width = attrs.width + 'px';
  2440. var video_url = $scope.video + "/playlist.m3u8";
  2441. //var video_url = $scope.video;
  2442.  
  2443. $scope.player = jwplayer('videoplayer').setup({
  2444. file: video_url,
  2445. width: "100%",
  2446. aspectratio: "16:9",
  2447. controls: $scope.mode == eVideoCompletionMode.AtStart,
  2448. autostart: true
  2449. }).onPlay(function () {
  2450. $timeout(function () {
  2451. $scope.isPlaying = true;
  2452. $scope.duration = $scope.player.getDuration();
  2453. if ($scope.onStart) {
  2454. $scope.onStart();
  2455. }
  2456. }, 10);
  2457. }).onPause(function () {
  2458. $timeout(function () {
  2459. $scope.isPlaying = false;
  2460. if ($scope.onStop) {
  2461. $scope.onStop();
  2462. }
  2463. }, 10);
  2464. }).onComplete(function () {
  2465. $timeout(function () {
  2466. $scope.isPlaying = false;
  2467. if ($scope.onComplete) {
  2468. $scope.onComplete();
  2469. }
  2470. }, 10);
  2471. }).onTime(function (e) {
  2472. $timeout(function () {
  2473. var positionSeconds = parseInt(e.position);
  2474. $scope.position = 100 * e.position / e.duration;
  2475. if ($scope.positionSeconds != positionSeconds) {
  2476. if ($scope.bookmark) {
  2477. $scope.bookmark.position = parseInt(e.position);
  2478. $scope.bookmark.duration = parseInt(e.duration);
  2479. }
  2480. $scope.positionSeconds = positionSeconds;
  2481. $scope.onPlaying();
  2482. }
  2483. }, 10);
  2484. });
  2485. }
  2486.  
  2487. return {
  2488. restrict: 'E',
  2489. templateUrl: '/App/Views/module/video/player.html',
  2490. scope: {
  2491. video: '=',
  2492. urlType: '=',
  2493. stream: '=',
  2494. mode: '=',
  2495. bookmark: '=',
  2496. onStart: '&',
  2497. onStop: '&',
  2498. onComplete: '&',
  2499. onPlaying: '&'
  2500. },
  2501. link: link,
  2502. controller: ['$scope', function ($scope) {
  2503. $scope.isPlaying = false;
  2504. $scope.position = 0;
  2505. $scope.positionSeconds = 0;
  2506. $scope.showHtmlControls = $scope.mode == eVideoCompletionMode.AtEnd;
  2507. $scope.play = function () {
  2508. $scope.player.play(true);
  2509. $scope.isPlaying = true;
  2510. };
  2511. $scope.pause = function () {
  2512. $scope.player.pause(true);
  2513. $scope.isPlaying = false;
  2514. };
  2515. }]
  2516. };
  2517. }]);
  2518.  
  2519. })(angular);
  2520. (function (angular) {
  2521.  
  2522. "use strict";
  2523.  
  2524. var app = angular.module('ApLearningFrontend');
  2525.  
  2526. app.controller('ScormLessonController', ['$scope', 'ApLearning', '$window', '$timeout',
  2527. function ($scope, ApLearning, $window, $timeout) {
  2528.  
  2529. function openPanel() {
  2530.  
  2531. var wnd = $window.open("/" + ApLearning.lang + '/Module/ScormPlayer/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2532. "Lesson",
  2533. "fullscreen=yes,location=no,menubar=no,resizable=yes,scrollbars=no,status=no,titlebar=no,toolbar=no");
  2534.  
  2535. wnd.focus();
  2536. wnd.onbeforeunload = function () {
  2537. $scope.statusChanged();
  2538. };
  2539. }
  2540.  
  2541. $timeout(openPanel, 1000);
  2542.  
  2543. }]);
  2544.  
  2545. })(angular);
  2546. (function (angular) {
  2547.  
  2548. "use strict";
  2549.  
  2550. var app = angular.module('ApLearningFrontend');
  2551.  
  2552. app.controller('SurveyModuleController', ['$scope', '$http', 'ApLearning', 'Labels', 'SessionManager', 'bootbox', 'eSurveyQuestionType', 'eSurveyDetailsMode',
  2553. function ($scope, $http, ApLearning, Labels, SessionManager, bootbox, eSurveyQuestionType, eSurveyDetailsMode) {
  2554.  
  2555. $scope.emptyRegex = /^[\s]*$/;
  2556. $scope.Labels = Labels;
  2557. $scope.eStep = {
  2558. INTRO: 1,
  2559. SURVEY: 2,
  2560. SUMMARY: 3,
  2561. FINAL: 4
  2562. };
  2563. $scope.eSurveyQuestionType = eSurveyQuestionType;
  2564. $scope.eSurveyDetailsMode = eSurveyDetailsMode;
  2565.  
  2566. $scope.questions = null;
  2567. $scope.final = null;
  2568. $scope.completed = false;
  2569. $scope.canRepeat = false;
  2570.  
  2571. $scope.currentStep = $scope.eStep.INTRO;
  2572. $scope.currentQuestion = null;
  2573. $scope.currentQuestionIndex = null;
  2574. $scope.allOk = false;
  2575. $scope.summaryReached = false;
  2576.  
  2577. $scope.startSurvey = function () {
  2578. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID).then(function () {
  2579. SessionManager.setStarted($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID).then(function () {
  2580. $scope.currentStep = $scope.eStep.SURVEY;
  2581. $scope.currentQuestionIndex = 0;
  2582. $scope.currentQuestion = $scope.questions[$scope.currentQuestionIndex];
  2583. $scope.statusChanged();
  2584. });
  2585. });
  2586. };
  2587.  
  2588. function checkAnswers() {
  2589. var quest, subq, i, j;
  2590.  
  2591. $scope.allOk = $scope.questions.length > 0;
  2592.  
  2593. for (i = 0; i < $scope.questions.length; i++) {
  2594. quest = $scope.questions[i];
  2595. quest.Ok = false;
  2596. switch (quest.Type) {
  2597. case eSurveyQuestionType.SingleChoice:
  2598. if (quest.HasSubquestions) {
  2599. quest.Ok = quest.SubQuestions.length > 0;
  2600. for (j = 0; j < quest.SubQuestions.length; j++) {
  2601. subq = quest.SubQuestions[j];
  2602. quest.Ok = quest.Ok && subq.AnswerID ? true : false;
  2603. if (subq.AnswerID == -1 && $scope.emptyRegex.test(subq.FreeAnswer || '')) {
  2604. quest.Ok = false;
  2605. }
  2606. if (quest.DetailsMode == eSurveyDetailsMode.DetailsRequired && $scope.emptyRegex.test(subq.Details || '')) {
  2607. quest.Ok = false;
  2608. }
  2609. if (!quest.Ok) {
  2610. break;
  2611. }
  2612. }
  2613. } else {
  2614. quest.Ok = quest.AnswerID ? true : false;
  2615. if (quest.AnswerID == -1 && $scope.emptyRegex.test(quest.FreeAnswer || '')) {
  2616. quest.Ok = false;
  2617. }
  2618. if (quest.DetailsMode == eSurveyDetailsMode.DetailsRequired && $scope.emptyRegex.test(quest.Details || '')) {
  2619. quest.Ok = false;
  2620. }
  2621. }
  2622. break;
  2623.  
  2624. case eSurveyQuestionType.MultipleChoice:
  2625. quest.Ok = true;
  2626. if (quest.FreeAnswerSelected && $scope.emptyRegex.test(quest.FreeAnswer || '')) {
  2627. quest.Ok = false;
  2628. }
  2629. if (quest.DetailsMode == eSurveyDetailsMode.DetailsRequired && $scope.emptyRegex.test(quest.Details || '')) {
  2630. quest.Ok = false;
  2631. }
  2632. break;
  2633.  
  2634. case eSurveyQuestionType.FreeText:
  2635. quest.Ok = !$scope.emptyRegex.test(quest.AnswerDetail || '');
  2636. break;
  2637. }
  2638.  
  2639. $scope.allOk = $scope.allOk && quest.Ok;
  2640. }
  2641. }
  2642.  
  2643. $scope.goToNext = function () {
  2644. if ($scope.currentQuestionIndex < $scope.questions.length - 1) {
  2645. $scope.currentQuestionIndex++;
  2646. $scope.currentQuestion = $scope.questions[$scope.currentQuestionIndex];
  2647. }
  2648. };
  2649.  
  2650. $scope.goToPrev = function () {
  2651. if ($scope.currentQuestionIndex > 0) {
  2652. $scope.currentQuestionIndex--;
  2653. $scope.currentQuestion = $scope.questions[$scope.currentQuestionIndex];
  2654. }
  2655. };
  2656.  
  2657. $scope.goToSummary = function () {
  2658. checkAnswers();
  2659. $scope.summaryReached = true;
  2660. $scope.currentStep = $scope.eStep.SUMMARY;
  2661. };
  2662.  
  2663. $scope.goToQuestion = function (index) {
  2664. $scope.currentStep = $scope.eStep.SURVEY;
  2665. $scope.currentQuestionIndex = index;
  2666. $scope.currentQuestion = $scope.questions[$scope.currentQuestionIndex];
  2667. };
  2668.  
  2669. $scope.submitAnswers = function () {
  2670. var i, j, quest, subq, ans, req = {
  2671. courseID: $scope.course.ID,
  2672. unitID: $scope.unit.Unit.ID,
  2673. moduleID: $scope.module.Module.ID,
  2674. sessionID: SessionManager.getSessionData().id,
  2675. sessionCode: SessionManager.getSessionData().sessionID,
  2676. answers: []
  2677. };
  2678.  
  2679. if (!$scope.allOk) {
  2680. return;
  2681. }
  2682.  
  2683. for (i = 0; i < $scope.questions.length; i++) {
  2684. quest = $scope.questions[i];
  2685. switch (quest.Type) {
  2686. case eSurveyQuestionType.SingleChoice:
  2687. if (quest.HasSubquestions) {
  2688. for (j = 0; j < quest.SubQuestions.length; j++) {
  2689. subq = quest.SubQuestions[j];
  2690. quest.Ok = quest.Ok && subq.AnswerID ? true : false;
  2691. req.answers.push({
  2692. QuestionID: quest.ID,
  2693. SubquestionID: subq.ID,
  2694. AnswerID: subq.AnswerID > 0 ? subq.AnswerID : null,
  2695. CustomAnswer: subq.FreeAnswer,
  2696. AnswerDetails: subq.Details
  2697. });
  2698. }
  2699. } else {
  2700. req.answers.push({
  2701. QuestionID: quest.ID,
  2702. AnswerID: quest.AnswerID > 0 ? quest.AnswerID : null,
  2703. CustomAnswer: quest.FreeAnswer,
  2704. AnswerDetails: quest.Details
  2705. });
  2706. }
  2707. break;
  2708.  
  2709. case eSurveyQuestionType.MultipleChoice:
  2710. for (j = 0; j < quest.Answers.length; j++) {
  2711. ans = quest.Answers[j];
  2712. if (ans.Selected) {
  2713. req.answers.push({
  2714. QuestionID: quest.ID,
  2715. AnswerID: ans.ID,
  2716. });
  2717. }
  2718. }
  2719. quest.Ok = true;
  2720. if (!$scope.emptyRegex.test(quest.FreeAnswer || '') || !$scope.emptyRegex.test(quest.Details || '')) {
  2721. req.answers.push({
  2722. QuestionID: quest.ID,
  2723. CustomAnswer: quest.FreeAnswer,
  2724. AnswerDetails: quest.Details
  2725. });
  2726. }
  2727. break;
  2728.  
  2729. case eSurveyQuestionType.FreeText:
  2730. req.answers.push({
  2731. QuestionID: quest.ID,
  2732. CustomAnswer: quest.AnswerDetail
  2733. });
  2734. break;
  2735. }
  2736. }
  2737.  
  2738. bootbox.confirm(Labels.surveySubmitConfirm, function (confirm) {
  2739. if (confirm) {
  2740. $http({
  2741. url: '/' + ApLearning.lang + '/Module/SaveSurveyAnswers',
  2742. method: 'POST',
  2743. data: JSON.stringify(req),
  2744. responseType: 'json',
  2745. headers: {
  2746. 'Content-Type': "application/json"
  2747. }
  2748. }).success(function (data) {
  2749. if (data.ok) {
  2750. SessionManager.stopSession();
  2751. $scope.currentStep = $scope.eStep.FINAL;
  2752. $scope.statusChanged();
  2753. } else {
  2754. bootbox.alert('Error: ' + data.error);
  2755. }
  2756. }).error(function () {
  2757. bootbox.alert('Network error');
  2758. });
  2759. }
  2760. });
  2761. };
  2762.  
  2763. function loadConfig() {
  2764. $http({
  2765. url: '/' + ApLearning.lang + '/Module/GetSurveyModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2766. method: 'GET',
  2767. responseType: 'json'
  2768. }).success(function (data) {
  2769. if (data.ok) {
  2770.  
  2771. $scope.questions = data.config.questions;
  2772. $scope.final = data.config.final;
  2773. $scope.completed = data.config.completed;
  2774. $scope.canRepeat = data.config.canRepeat;
  2775.  
  2776. } else {
  2777. bootbox.alert('Error: ' + data.error);
  2778. }
  2779. }).error(function () {
  2780. bootbox.alert('Network error');
  2781. });
  2782. }
  2783.  
  2784. loadConfig();
  2785. }]);
  2786.  
  2787. })(angular);
  2788. (function (angular) {
  2789.  
  2790. "use strict";
  2791.  
  2792. var app = angular.module('ApLearningFrontend');
  2793.  
  2794. app.controller('GuidedNoteModuleController', ['$scope', '$http', 'ApLearning', 'bootbox', 'SessionManager', 'eGuidedNoteFieldType', 'Labels',
  2795. function ($scope, $http, ApLearning, bootbox, SessionManager, eGuidedNoteFieldType, Labels) {
  2796.  
  2797. $scope.Labels = Labels;
  2798. $scope.eGuidedNoteFieldType = eGuidedNoteFieldType;
  2799. $scope.saving = false;
  2800. $scope.saved = false;
  2801. $scope.show = false;
  2802. $scope.fields = null;
  2803. $scope.currentSession = null;
  2804. $scope.submitted = false;
  2805.  
  2806. $scope.saveValues = function (frm) {
  2807. var req = {
  2808. courseID: $scope.course.ID,
  2809. unitID: $scope.unit.Unit.ID,
  2810. moduleID: $scope.module.Module.ID,
  2811. sessionID: SessionManager.getSessionData().id,
  2812. sessionCode: SessionManager.getSessionData().sessionID,
  2813. values: []
  2814. };
  2815. $scope.submitted = true;
  2816. if (frm.$valid) {
  2817. $scope.saving = true;
  2818. $scope.fields.forEach(function (f) {
  2819. req.values.push({
  2820. FieldID: f.ID,
  2821. Value: f.Value
  2822. });
  2823. });
  2824.  
  2825. $http({
  2826. url: '/' + ApLearning.lang + '/Module/SaveGuidedNoteUserValues',
  2827. method: 'POST',
  2828. headers: {'Content-Type': "application/json"},
  2829. data: JSON.stringify(req)
  2830. }).success(function (data) {
  2831. $scope.saving = false;
  2832. if (data.ok) {
  2833. $scope.saved = true;
  2834. $scope.statusChanged();
  2835. } else {
  2836. bootbox.alert('Error: ' + data.error);
  2837. }
  2838. }).error(function () {
  2839. $scope.saving = false;
  2840. });
  2841. }
  2842. };
  2843.  
  2844. function loadConfig() {
  2845. $http({
  2846. url: '/' + ApLearning.lang + '/Module/GetGuidedNoteModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2847. method: 'GET',
  2848. responseType: 'json'
  2849. }).success(function (data) {
  2850. if (data.ok) {
  2851.  
  2852. $scope.fields = data.config.fields;
  2853.  
  2854. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2855. .then(function (sessionCreated) {
  2856.  
  2857. $scope.currentSession = sessionCreated;
  2858. $scope.show = true;
  2859.  
  2860. }, function (error) {
  2861. bootbox.alert("Error starting session: " + error);
  2862. });
  2863.  
  2864. } else {
  2865. bootbox.alert('Error: ' + data.error);
  2866. }
  2867. }).error(function () {
  2868. bootbox.alert('Network error');
  2869. });
  2870. }
  2871.  
  2872. loadConfig();
  2873.  
  2874. }]);
  2875.  
  2876. })(angular);
  2877. (function (angular) {
  2878.  
  2879. "use strict";
  2880.  
  2881. var app = angular.module('ApLearningFrontend');
  2882.  
  2883. app.controller('GuidedNoteExportModuleController', ['$scope', '$http', '$window', 'ApLearning', 'SessionManager',
  2884. function ($scope, $http, $window, ApLearning, SessionManager) {
  2885.  
  2886. $scope.show = false;
  2887. $scope.config = null;
  2888. $scope.currentSession = null;
  2889. $scope.saving = false;
  2890.  
  2891. $scope.export = function () {
  2892. var urlPart = $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID + '-' + SessionManager.getSessionData().id + '-' + SessionManager.getSessionData().sessionID;
  2893. var setExportedUrl = '/' + ApLearning.lang + '/Module/SetGuidedNoteExported/' + urlPart;
  2894. var downloadUrl = '/' + ApLearning.lang + '/Module/GetGuidedNoteExportFile/' + urlPart;
  2895.  
  2896. $scope.saving = true;
  2897. $http({
  2898. url: setExportedUrl,
  2899. method: 'POST'
  2900. }).success(function (data) {
  2901. $scope.saving = false;
  2902. if (data.ok) {
  2903. $scope.statusChanged();
  2904. $window.location.href = downloadUrl;
  2905. } else {
  2906. bootbox.alert('Error: ' + data.error);
  2907. }
  2908. }).error(function () {
  2909. $scope.saving = false;
  2910. bootbox.alert('Network error');
  2911. });
  2912. };
  2913.  
  2914. function loadConfig() {
  2915. $http({
  2916. url: '/' + ApLearning.lang + '/Module/GetGuidedNoteExportModule/' + $scope.course.ID + '-' + $scope.unit.Unit.ID + '-' + $scope.module.Module.ID,
  2917. method: 'GET',
  2918. responseType: 'json'
  2919. }).success(function (data) {
  2920. if (data.ok) {
  2921.  
  2922. $scope.config = data.config;
  2923.  
  2924. SessionManager.startSession($scope.course.ID, $scope.unit.Unit.ID, $scope.module.Module.ID)
  2925. .then(function (sessionCreated) {
  2926.  
  2927. $scope.currentSession = sessionCreated;
  2928. $scope.show = true;
  2929.  
  2930. }, function (error) {
  2931. bootbox.alert("Error starting session: " + error);
  2932. });
  2933.  
  2934. } else {
  2935. bootbox.alert('Error: ' + data.error);
  2936. }
  2937. }).error(function () {
  2938. bootbox.alert('Network error');
  2939. });
  2940. }
  2941.  
  2942. loadConfig();
  2943.  
  2944. }]);
  2945.  
  2946. })(angular);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement