Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
5cd58897
Commit
5cd58897
authored
Jan 13, 2015
by
Daniel Friedman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Require unique group names in group configurations
TNL-1142
parent
c95d90a3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
46 deletions
+66
-46
cms/static/js/factories/group_configurations.js
+3
-1
cms/static/js/models/group_configuration.js
+21
-8
cms/static/js/spec/models/group_configuration_spec.js
+37
-33
cms/static/js/spec/views/group_configuration_spec.js
+1
-1
cms/static/js/views/list_item.js
+1
-1
cms/static/js/views/list_item_editor.js
+3
-2
No files found.
cms/static/js/factories/group_configurations.js
View file @
5cd58897
...
...
@@ -7,7 +7,9 @@ define([
var
experimentGroupConfigurations
=
new
GroupConfigurationCollection
(
experimentGroupConfigurationsJson
,
{
parse
:
true
}
),
contentGroupConfiguration
=
new
GroupConfigurationModel
(
contentGroupConfigurationJson
,
{
parse
:
true
});
contentGroupConfiguration
=
new
GroupConfigurationModel
(
contentGroupConfigurationJson
,
{
parse
:
true
,
canBeEmpty
:
true
});
experimentGroupConfigurations
.
url
=
groupConfigurationUrl
;
experimentGroupConfigurations
.
outlineUrl
=
courseOutlineUrl
;
...
...
cms/static/js/models/group_configuration.js
View file @
5cd58897
...
...
@@ -35,7 +35,8 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
collectionType
:
GroupCollection
}],
initialize
:
function
()
{
initialize
:
function
(
attributes
,
options
)
{
this
.
canBeEmpty
=
options
&&
options
.
canBeEmpty
;
this
.
setOriginalAttributes
();
return
this
;
},
...
...
@@ -45,7 +46,7 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
},
reset
:
function
()
{
this
.
set
(
this
.
_originalAttributes
,
{
parse
:
true
});
this
.
set
(
this
.
_originalAttributes
,
{
parse
:
true
,
validate
:
true
});
},
isDirty
:
function
()
{
...
...
@@ -87,23 +88,35 @@ function(Backbone, _, str, gettext, GroupModel, GroupCollection) {
};
}
if
(
attrs
.
groups
.
length
<
1
)
{
if
(
!
this
.
canBeEmpty
&&
attrs
.
groups
.
length
<
1
)
{
return
{
message
:
gettext
(
'There must be at least one group.'
),
attributes
:
{
groups
:
true
}
};
}
else
{
// validate all groups
var
invalidGroups
=
[];
var
validGroups
=
new
Backbone
.
Collection
(),
invalidGroups
=
new
Backbone
.
Collection
();
attrs
.
groups
.
each
(
function
(
group
)
{
if
(
!
group
.
isValid
())
{
invalidGroups
.
push
(
group
);
if
(
!
group
.
isValid
())
{
invalidGroups
.
add
(
group
);
}
else
{
validGroups
.
add
(
group
);
}
});
if
(
!
_
.
isEmpty
(
invalidGroups
))
{
if
(
!
invalidGroups
.
isEmpty
())
{
return
{
message
:
gettext
(
'All groups must have a name.'
),
attributes
:
{
groups
:
invalidGroups
}
attributes
:
{
groups
:
invalidGroups
.
toJSON
()
}
};
}
var
groupNames
=
validGroups
.
map
(
function
(
group
)
{
return
group
.
get
(
'name'
);
});
if
(
groupNames
.
length
!==
_
.
uniq
(
groupNames
).
length
)
{
return
{
message
:
gettext
(
'All groups must have a unique name.'
),
attributes
:
{
groups
:
validGroups
.
toJSON
()
}
};
}
}
...
...
cms/static/js/spec/models/group_configuration_spec.js
View file @
5cd58897
...
...
@@ -48,10 +48,12 @@ define([
});
it
(
'should be able to reset itself'
,
function
()
{
this
.
model
.
set
(
'name'
,
'foobar'
);
this
.
model
.
reset
();
var
originalName
=
'Original Name'
,
model
=
new
GroupConfigurationModel
({
name
:
originalName
});
model
.
set
({
name
:
'New Name'
});
model
.
reset
();
expect
(
this
.
model
.
get
(
'name'
)).
toEqual
(
''
);
expect
(
model
.
get
(
'name'
)).
toEqual
(
originalName
);
});
it
(
'should be dirty after it
\'
s been changed'
,
function
()
{
...
...
@@ -149,10 +151,42 @@ define([
});
it
(
'can pass validation'
,
function
()
{
// Note that two groups - Group A and Group B - are
// created by default.
var
model
=
new
GroupConfigurationModel
({
name
:
'foo'
});
expect
(
model
.
isValid
()).
toBeTruthy
();
});
it
(
'requires at least one group'
,
function
()
{
var
group1
=
new
GroupModel
({
name
:
'Group A'
}),
model
=
new
GroupConfigurationModel
({
name
:
'foo'
,
groups
:
[]
});
expect
(
model
.
isValid
()).
toBeFalsy
();
model
.
get
(
'groups'
).
add
(
group1
);
expect
(
model
.
isValid
()).
toBeTruthy
();
});
it
(
'requires a valid group'
,
function
()
{
var
model
=
new
GroupConfigurationModel
({
name
:
'foo'
,
groups
:
[{
name
:
''
}]
});
expect
(
model
.
isValid
()).
toBeFalsy
();
});
it
(
'requires all groups to be valid'
,
function
()
{
var
model
=
new
GroupConfigurationModel
({
name
:
'foo'
,
groups
:
[{
name
:
'Group A'
},
{
name
:
''
}]
});
expect
(
model
.
isValid
()).
toBeFalsy
();
});
it
(
'requires all groups to have unique names'
,
function
()
{
var
model
=
new
GroupConfigurationModel
({
name
:
'foo'
,
groups
:
[{
name
:
'Group A'
},
{
name
:
'Group A'
}]
});
expect
(
model
.
isValid
()).
toBeFalsy
();
});
});
});
...
...
@@ -184,36 +218,6 @@ define([
expect
(
model
.
isValid
()).
toBeTruthy
();
});
it
(
'requires at least one group'
,
function
()
{
var
group1
=
new
GroupModel
({
name
:
'Group A'
}),
model
=
new
GroupConfigurationModel
({
name
:
'foo'
});
model
.
get
(
'groups'
).
reset
([]);
expect
(
model
.
isValid
()).
toBeFalsy
();
model
.
get
(
'groups'
).
add
(
group1
);
expect
(
model
.
isValid
()).
toBeTruthy
();
});
it
(
'requires a valid group'
,
function
()
{
var
group
=
new
GroupModel
(),
model
=
new
GroupConfigurationModel
({
name
:
'foo'
});
model
.
get
(
'groups'
).
reset
([
group
]);
expect
(
model
.
isValid
()).
toBeFalsy
();
});
it
(
'requires all groups to be valid'
,
function
()
{
var
group1
=
new
GroupModel
({
name
:
'Group A'
}),
group2
=
new
GroupModel
(),
model
=
new
GroupConfigurationModel
({
name
:
'foo'
});
model
.
get
(
'groups'
).
reset
([
group1
,
group2
]);
expect
(
model
.
isValid
()).
toBeFalsy
();
});
});
});
...
...
cms/static/js/spec/views/group_configuration_spec.js
View file @
5cd58897
...
...
@@ -659,7 +659,7 @@ define([
id
:
0
,
name
:
'Content Group Configuration'
,
groups
:
groups
});
}
,
{
canBeEmpty
:
true
}
);
groupConfiguration
.
urlRoot
=
'/mock_url'
;
return
groups
;
};
...
...
cms/static/js/views/list_item.js
View file @
5cd58897
...
...
@@ -18,7 +18,7 @@ define([
)
{
'use strict'
;
var
ListItemView
=
BaseView
.
extend
({
var
ListItemView
=
BaseView
.
extend
({
canDelete
:
false
,
initialize
:
function
()
{
...
...
cms/static/js/views/list_item_editor.js
View file @
5cd58897
...
...
@@ -17,11 +17,12 @@ define([
var
ListItemEditorView
=
BaseView
.
extend
({
initialize
:
function
()
{
this
.
listenTo
(
this
.
model
,
'invalid'
,
this
.
render
);
this
.
listenTo
(
this
.
getSaveableModel
(),
'invalid'
,
this
.
render
);
},
render
:
function
()
{
this
.
$el
.
html
(
this
.
template
(
_
.
extend
({
error
:
this
.
model
.
validationError
error
:
this
.
model
.
validationError
||
this
.
getSaveableModel
().
validationError
},
this
.
getTemplateOptions
())));
},
...
...
@@ -29,7 +30,7 @@ define([
if
(
event
&&
event
.
preventDefault
)
{
event
.
preventDefault
();
}
this
.
setValues
();
if
(
!
this
.
model
.
isValid
())
{
if
(
!
this
.
model
.
isValid
()
||
!
this
.
getSaveableModel
().
isValid
()
)
{
return
false
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment