Skip to content

Commit 80b5c99

Browse files
author
per ploug
committed
Sanitizes empty grid items
1 parent 658a045 commit 80b5c99

File tree

2 files changed

+68
-74
lines changed

2 files changed

+68
-74
lines changed

src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.controller.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -397,13 +397,17 @@ angular.module("umbraco")
397397
}
398398

399399
if ($scope.model.value && $scope.model.value.sections && $scope.model.value.sections.length > 0) {
400-
_.forEach($scope.model.value.sections, function(section){
400+
_.forEach($scope.model.value.sections, function(section, index){
401401

402-
$scope.initSection(section);
402+
if(section.grid > 0){
403+
$scope.initSection(section);
403404

404-
//we do this to ensure that the grid can be reset by deleting the last row
405-
if(section.rows.length > 0){
406-
clear = false;
405+
//we do this to ensure that the grid can be reset by deleting the last row
406+
if(section.rows.length > 0){
407+
clear = false;
408+
}
409+
}else{
410+
$scope.model.value.sections.splice(index, 1);
407411
}
408412
});
409413
}
@@ -435,7 +439,7 @@ angular.module("umbraco")
435439

436440
//if init fails, remove
437441
if(!initd){
438-
section.rows.splic(index, 1);
442+
section.rows.splice(index, 1);
439443
}else{
440444
section.rows[index] = initd;
441445
}
@@ -465,38 +469,43 @@ angular.module("umbraco")
465469
//sync area configuration
466470
_.each(original.areas, function(area, areaIndex){
467471

468-
var currentArea = row.areas[areaIndex];
469-
area.config = currentArea.config;
470-
area.styles = currentArea.styles;
471472

472-
//copy over existing controls into the new areas
473-
if(row.areas.length > areaIndex && row.areas[areaIndex].controls){
474-
area.controls = currentArea.controls;
473+
if(area.grid > 0){
474+
var currentArea = row.areas[areaIndex];
475+
area.config = currentArea.config;
476+
area.styles = currentArea.styles;
475477

476-
_.forEach(area.controls, function(control, controlIndex){
477-
$scope.initControl(control, controlIndex);
478-
});
478+
//copy over existing controls into the new areas
479+
if(row.areas.length > areaIndex && row.areas[areaIndex].controls){
480+
area.controls = currentArea.controls;
479481

480-
}else{
481-
area.controls = [];
482-
}
482+
_.forEach(area.controls, function(control, controlIndex){
483+
$scope.initControl(control, controlIndex);
484+
});
483485

484-
//set width
485-
area.$percentage = $scope.percentage(area.grid);
486-
area.$uniqueId = $scope.setUniqueId();
486+
}else{
487+
area.controls = [];
488+
}
487489

488-
//set editor permissions
489-
if(!area.allowed || area.allowAll === true){
490-
area.$allowedEditors = $scope.availableEditors;
491-
area.$allowsRTE = true;
492-
}else{
493-
area.$allowedEditors = _.filter($scope.availableEditors, function(editor){
494-
return _.indexOf(area.allowed, editor.alias) >= 0;
495-
});
490+
//set width
491+
area.$percentage = $scope.percentage(area.grid);
492+
area.$uniqueId = $scope.setUniqueId();
496493

497-
if(_.indexOf(area.allowed,"rte")>=0){
494+
//set editor permissions
495+
if(!area.allowed || area.allowAll === true){
496+
area.$allowedEditors = $scope.availableEditors;
498497
area.$allowsRTE = true;
498+
}else{
499+
area.$allowedEditors = _.filter($scope.availableEditors, function(editor){
500+
return _.indexOf(area.allowed, editor.alias) >= 0;
501+
});
502+
503+
if(_.indexOf(area.allowed,"rte")>=0){
504+
area.$allowsRTE = true;
505+
}
499506
}
507+
}else{
508+
original.areas.splice(areaIndex, 1);
500509
}
501510
});
502511

src/Umbraco.Web.UI.Client/src/views/propertyeditors/grid/grid.prevalues.controller.js

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,12 @@ angular.module("umbraco")
9595
);
9696

9797
};
98+
9899
$scope.deleteTemplate = function(index){
99100
$scope.model.value.templates.splice(index, 1);
100101
};
101102

102103

103-
104-
105-
106-
107-
108104
/****************
109105
Row
110106
*****************/
@@ -135,26 +131,12 @@ angular.module("umbraco")
135131
$scope.deleteLayout = function(index){
136132
$scope.model.value.layouts.splice(index, 1);
137133
};
138-
139-
140134

141135

142136

143137
/****************
144138
utillities
145139
*****************/
146-
$scope.scaleUp = function(section, max, overflow){
147-
var add = 1;
148-
if(overflow !== true){
149-
add = (max > 1) ? 1 : max;
150-
}
151-
//var add = (max > 1) ? 1 : max;
152-
section.grid = section.grid+add;
153-
};
154-
$scope.scaleDown = function(section){
155-
var remove = (section.grid > 1) ? 1 : section.grid;
156-
section.grid = section.grid-remove;
157-
};
158140
$scope.toggleCollection = function(collection, toggle){
159141
if(toggle){
160142
collection = [];
@@ -168,11 +150,14 @@ angular.module("umbraco")
168150
};
169151

170152

153+
/****************
154+
Config
155+
*****************/
156+
171157
$scope.removeConfigValue = function(collection, index){
172158
collection.splice(index, 1);
173159
};
174160

175-
176161
var editConfigCollection = function(configValues, title, callbackOnSave){
177162
dialogService.open(
178163
{
@@ -198,30 +183,6 @@ angular.module("umbraco")
198183
};
199184

200185

201-
/****************
202-
watchers
203-
*****************/
204-
$scope.$watch("currentTemplate", function(template){
205-
if(template){
206-
var total = 0;
207-
_.forEach(template.sections, function(section){
208-
total = (total + section.grid);
209-
});
210-
$scope.availableTemplateSpace = $scope.model.value.columns - total;
211-
}
212-
}, true);
213-
214-
$scope.$watch("currentLayout", function(layout){
215-
if(layout){
216-
var total = 0;
217-
_.forEach(layout.areas, function(area){
218-
total = (total + area.grid);
219-
});
220-
$scope.availableLayoutSpace = $scope.model.value.columns - total;
221-
}
222-
}, true);
223-
224-
225186
/****************
226187
editors
227188
*****************/
@@ -249,4 +210,28 @@ angular.module("umbraco")
249210
}
250211
}
251212

213+
/****************
214+
Clean up
215+
*****************/
216+
$scope.$on("formSubmitting", function (ev, args) {
217+
var ts = $scope.model.value.templates;
218+
var ls = $scope.model.value.layouts;
219+
220+
_.each(ts, function(t){
221+
_.each(t.sections, function(section, index){
222+
if(section.grid === 0){
223+
t.sections.splice(index, 1);
224+
}
225+
});
226+
});
227+
228+
_.each(ls, function(l){
229+
_.each(l.areas, function(area, index){
230+
if(area.grid === 0){
231+
l.areas.splice(index, 1);
232+
}
233+
});
234+
});
235+
});
236+
252237
});

0 commit comments

Comments
 (0)