Skip to content

Commit dc43d4d

Browse files
committed
lesson edit: fix unit selection
1 parent bd834c9 commit dc43d4d

1 file changed

Lines changed: 14 additions & 10 deletions

File tree

administration/static/app/controllers/admin.lesson.controllers.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,11 @@
108108
document.title = 'Aula: {0}'.format(l.name);
109109

110110
if(l.units.length > 0) {
111-
if ($location.search().unit) {
112-
$scope.selectUnit(l.units[$location.search().unit])
113-
}
114-
else {
115-
$scope.selectUnit(l.units[0]);
116-
}
111+
var u = $location.search().unit ?
112+
l.units[$location.search().unit] : undefined;
113+
114+
u = u ? l.units[$location.search().unit] : l.units[0];
115+
$scope.selectUnit(u)
117116
} else {
118117
$scope.addUnit();
119118
}
@@ -174,8 +173,14 @@
174173
};
175174

176175
$scope.selectUnit = function(u) {
177-
Unit.get({id : u.id}, function(data){
178-
u = data;
176+
if (u && u.id) {
177+
Unit.get({id : u.id}, function(data){
178+
setupUnit(data)
179+
});
180+
} else {
181+
setupUnit(u);
182+
}
183+
function setupUnit(u){
179184
$scope.currentUnit = u;
180185

181186
for(i = 0; i < $scope.lesson.units.length; i++){
@@ -197,8 +202,7 @@
197202

198203
// MarkdownDirective.resetEditors();
199204
MarkdownDirective.refreshEditorsPreview();
200-
201-
});
205+
}
202206
};
203207

204208
$scope.addUnit = function() {

0 commit comments

Comments
 (0)