|
1 | 1 | /* global $, angular */
|
2 |
| -var script = document.querySelector('script[data-under13]'); |
| 2 | +var script = document.querySelector("script[data-under13]"); |
3 | 3 | var userSharingDisabled = JSON.parse(script.dataset.sharingdisabled);
|
4 | 4 |
|
5 | 5 | // Declare app level module which depends on filters, and services
|
6 |
| -angular.module('projectsApp', [ |
7 |
| - 'ngRoute', |
8 |
| - 'ngResource', |
9 |
| - 'projectsApp.controllers', |
10 |
| - 'projectsApp.services' |
11 |
| -]).config(['$routeProvider', function ($routeProvider) { |
12 |
| - $routeProvider.when('/', |
13 |
| - {templateUrl: '/projects/angular', controller: 'ProjectsController'}); |
14 |
| - $routeProvider.otherwise({redirectTo: '/'}); |
15 |
| -}]); |
| 6 | +angular |
| 7 | + .module("projectsApp", [ |
| 8 | + "ngRoute", |
| 9 | + "ngResource", |
| 10 | + "projectsApp.controllers", |
| 11 | + "projectsApp.services" |
| 12 | + ]) |
| 13 | + .config([ |
| 14 | + "$routeProvider", |
| 15 | + function($routeProvider) { |
| 16 | + $routeProvider.when("/", { |
| 17 | + templateUrl: "/projects/angular", |
| 18 | + controller: "ProjectsController" |
| 19 | + }); |
| 20 | + $routeProvider.otherwise({ redirectTo: "/" }); |
| 21 | + } |
| 22 | + ]); |
16 | 23 |
|
17 | 24 | // SERVICES
|
18 |
| -var services = angular.module('projectsApp.services', []) |
19 |
| - .value('version', '0.1'); |
| 25 | +var services = angular |
| 26 | + .module("projectsApp.services", []) |
| 27 | + .value("version", "0.1"); |
20 | 28 |
|
21 | 29 | // Section service. see sites.v3/code.org/routes/v2_section_routes.rb
|
22 |
| -services.factory('projectsService', ['$resource', |
23 |
| - function ($resource) { |
24 |
| - var Project = $resource('/v3/channels/:id', {}, { |
25 |
| - // default methods: see https://code.angularjs.org/1.2.21/docs/api/ngResource/service/$resource |
26 |
| - // 'get': {method: 'GET'}, |
27 |
| - // 'save': {method: 'POST'}, |
28 |
| - // 'query': {method: 'GET', isArray:true}, |
29 |
| - // 'remove': {method: 'DELETE'}, |
30 |
| - // 'delete': {method: 'DELETE'} // don't use this because it doesn't work in IE9 |
31 |
| - }); |
32 |
| - |
33 |
| - Project.prototype.url = function () { |
| 30 | +services.factory("projectsService", [ |
| 31 | + "$resource", |
| 32 | + function($resource) { |
| 33 | + var Project = $resource( |
| 34 | + "/v3/channels/:id", |
| 35 | + {}, |
| 36 | + { |
| 37 | + // default methods: see https://code.angularjs.org/1.2.21/docs/api/ngResource/service/$resource |
| 38 | + // 'get': {method: 'GET'}, |
| 39 | + // 'save': {method: 'POST'}, |
| 40 | + // 'query': {method: 'GET', isArray:true}, |
| 41 | + // 'remove': {method: 'DELETE'}, |
| 42 | + // 'delete': {method: 'DELETE'} // don't use this because it doesn't work in IE9 |
| 43 | + } |
| 44 | + ); |
| 45 | + |
| 46 | + Project.prototype.url = function() { |
34 | 47 | if (this.level && this.id) {
|
35 |
| - return this.level.replace(/\/p\//, '/projects/') + '/' + this.id; |
| 48 | + return this.level.replace(/\/p\//, "/projects/") + "/" + this.id; |
36 | 49 | } else {
|
37 | 50 | return null;
|
38 | 51 | }
|
39 | 52 | };
|
40 | 53 |
|
41 |
| - Project.prototype.editUrl = function () { |
| 54 | + Project.prototype.editUrl = function() { |
42 | 55 | if (this.url()) {
|
43 | 56 | return this.url() + "/edit";
|
44 | 57 | } else {
|
45 | 58 | return null;
|
46 | 59 | }
|
47 | 60 | };
|
48 | 61 |
|
49 |
| - Project.prototype.thumbnail = function () { |
| 62 | + Project.prototype.thumbnail = function() { |
50 | 63 | if (this.thumbnailUrl) {
|
51 | 64 | return this.thumbnailUrl;
|
52 | 65 | } else {
|
53 |
| - return '/blockly/media/projects/project_default.png'; |
| 66 | + return "/blockly/media/projects/project_default.png"; |
54 | 67 | }
|
55 | 68 | };
|
56 | 69 |
|
57 |
| - Project.prototype.getType = function () { |
| 70 | + Project.prototype.getType = function() { |
58 | 71 | // Until projectType is back-filled, check level when projectType is missing.
|
59 |
| - return this.projectType ? |
60 |
| - this.projectType : |
61 |
| - this.level && this.level.substr('/projects/'.length); |
| 72 | + return this.projectType |
| 73 | + ? this.projectType |
| 74 | + : this.level && this.level.substr("/projects/".length); |
62 | 75 | };
|
63 | 76 |
|
64 |
| - Project.prototype.isPublishableProjectType = function () { |
| 77 | + Project.prototype.isPublishableProjectType = function() { |
65 | 78 | var projectType = this.getType();
|
66 |
| - var publishableTypes = userSharingDisabled ? |
67 |
| - window.AlwaysPublishableProjectTypes : |
68 |
| - window.AllPublishableProjectTypes; |
| 79 | + var publishableTypes = userSharingDisabled |
| 80 | + ? window.AlwaysPublishableProjectTypes |
| 81 | + : window.AllPublishableProjectTypes; |
69 | 82 | return publishableTypes.indexOf(projectType) > -1;
|
70 | 83 | };
|
71 | 84 |
|
72 | 85 | return Project;
|
73 |
| - }]); |
| 86 | + } |
| 87 | +]); |
74 | 88 |
|
75 | 89 | // CONTROLLERS
|
76 | 90 |
|
77 |
| -var controllers = angular.module('projectsApp.controllers', []) |
78 |
| - .value('version', '0.1'); |
79 |
| - |
80 |
| -controllers.controller('ProjectsController', ['$scope', '$http', '$route', '$routeParams', '$location', '$window', 'projectsService', |
81 |
| - function ($scope, $http, $route, $routeParams, $location, $window, projectsService) { |
82 |
| - $scope.projectsLoaded = false; |
83 |
| - |
84 |
| - $scope.projects = projectsService.query(); |
85 |
| - |
86 |
| - // set initial sort order |
87 |
| - $scope.order = 'updatedAt'; |
88 |
| - $scope.reverse = true; |
89 |
| - |
90 |
| - $scope.projects.$promise.then(function (projects) { |
91 |
| - $scope.projectsLoaded = true; |
92 |
| - }).catch($scope.genericError); |
93 |
| - |
94 |
| - $scope.projectVisible = function (project) { |
95 |
| - return (!project.hidden); |
96 |
| - }; |
97 |
| - |
98 |
| - $scope.genericError = function (result) { |
99 |
| - $window.alert("An unexpected error occurred, please try again. If this keeps happening, try reloading the page."); |
100 |
| - }; |
101 |
| - |
102 |
| - $scope.removeProject = function (project) { |
103 |
| - project.$remove({id: project.id}, function () { |
104 |
| - $scope.projects.splice($.inArray(project, $scope.projects), 1); |
105 |
| - }); |
106 |
| - }; |
107 |
| - |
108 |
| - $scope.showPublishProjectDialog = function (project) { |
109 |
| - var projectType = getProjectType(project); |
110 |
| - window.onShowConfirmPublishDialog(project.id, projectType); |
111 |
| - }; |
112 |
| - |
113 |
| - // Make this method available to projects/index.js. This can go away |
114 |
| - // once this file is moved to React. |
115 |
| - window.setProjectPublishedAt = function (projectId, publishedAt) { |
116 |
| - for (var i = 0; i < $scope.projects.length; i++) { |
117 |
| - var project = $scope.projects[i]; |
118 |
| - if (project.id === projectId) { |
119 |
| - project.publishedAt = publishedAt; |
120 |
| - break; |
121 |
| - } |
122 |
| - } |
| 91 | +var controllers = angular |
| 92 | + .module("projectsApp.controllers", []) |
| 93 | + .value("version", "0.1"); |
| 94 | + |
| 95 | +controllers.controller("ProjectsController", [ |
| 96 | + "$scope", |
| 97 | + "$http", |
| 98 | + "$route", |
| 99 | + "$routeParams", |
| 100 | + "$location", |
| 101 | + "$window", |
| 102 | + "projectsService", |
| 103 | + function( |
| 104 | + $scope, |
| 105 | + $http, |
| 106 | + $route, |
| 107 | + $routeParams, |
| 108 | + $location, |
| 109 | + $window, |
| 110 | + projectsService |
| 111 | + ) { |
| 112 | + $scope.projectsLoaded = false; |
| 113 | + |
| 114 | + $scope.projects = projectsService.query(); |
| 115 | + |
| 116 | + // set initial sort order |
| 117 | + $scope.order = "updatedAt"; |
| 118 | + $scope.reverse = true; |
| 119 | + |
| 120 | + $scope.projects.$promise |
| 121 | + .then(function(projects) { |
| 122 | + $scope.projectsLoaded = true; |
| 123 | + }) |
| 124 | + .catch($scope.genericError); |
| 125 | + |
| 126 | + $scope.projectVisible = function(project) { |
| 127 | + return !project.hidden; |
| 128 | + }; |
| 129 | + |
| 130 | + $scope.genericError = function(result) { |
| 131 | + $window.alert( |
| 132 | + "An unexpected error occurred, please try again. If this keeps happening, try reloading the page." |
| 133 | + ); |
| 134 | + }; |
123 | 135 |
|
124 |
| - // Refresh the UI |
125 |
| - $scope.$apply(); |
126 |
| - }; |
127 |
| - |
128 |
| - $scope.unpublishProject = function (project) { |
129 |
| - $http({ |
130 |
| - method:'POST', |
131 |
| - url: '/v3/channels/' + project.id + '/unpublish', |
132 |
| - }).then(function (response) { |
133 |
| - if (response.data) { |
134 |
| - project.publishedAt = null; |
| 136 | + $scope.removeProject = function(project) { |
| 137 | + project.$remove({ id: project.id }, function() { |
| 138 | + $scope.projects.splice($.inArray(project, $scope.projects), 1); |
| 139 | + }); |
| 140 | + }; |
| 141 | + |
| 142 | + $scope.showPublishProjectDialog = function(project) { |
| 143 | + var projectType = getProjectType(project); |
| 144 | + window.onShowConfirmPublishDialog(project.id, projectType); |
| 145 | + }; |
| 146 | + |
| 147 | + // Make this method available to projects/index.js. This can go away |
| 148 | + // once this file is moved to React. |
| 149 | + window.setProjectPublishedAt = function(projectId, publishedAt) { |
| 150 | + for (var i = 0; i < $scope.projects.length; i++) { |
| 151 | + var project = $scope.projects[i]; |
| 152 | + if (project.id === projectId) { |
| 153 | + project.publishedAt = publishedAt; |
| 154 | + break; |
| 155 | + } |
135 | 156 | }
|
136 |
| - }); |
137 |
| - }; |
138 |
| -}]); |
| 157 | + |
| 158 | + // Refresh the UI |
| 159 | + $scope.$apply(); |
| 160 | + }; |
| 161 | + |
| 162 | + $scope.unpublishProject = function(project) { |
| 163 | + $http({ |
| 164 | + method: "POST", |
| 165 | + url: "/v3/channels/" + project.id + "/unpublish" |
| 166 | + }).then(function(response) { |
| 167 | + if (response.data) { |
| 168 | + project.publishedAt = null; |
| 169 | + } |
| 170 | + }); |
| 171 | + }; |
| 172 | + } |
| 173 | +]); |
139 | 174 |
|
140 | 175 | function getProjectType(project) {
|
141 |
| - return project.level.split('/')[2]; |
| 176 | + return project.level.split("/")[2]; |
142 | 177 | }
|
0 commit comments