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
7b3c81ca
Commit
7b3c81ca
authored
Feb 06, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
blacklist violations now properly trigger violation error
delete keys only after save completes
parent
7668c70f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
22 deletions
+43
-22
cms/static/js/models/settings/advanced.js
+37
-0
cms/static/js/views/settings/advanced_view.js
+6
-22
No files found.
cms/static/js/models/settings/advanced.js
View file @
7b3c81ca
...
...
@@ -16,5 +16,42 @@ CMS.Models.Settings.Advanced = Backbone.Model.extend({
}
}
if
(
!
_
.
isEmpty
(
errors
))
return
errors
;
},
save
:
function
(
attrs
,
options
)
{
// wraps the save call w/ the deletion of the removed keys after we know the saved ones worked
options
=
options
?
_
.
clone
(
options
)
:
{};
// add saveSuccess to the success
var
success
=
options
.
success
;
var
model
=
this
;
options
.
success
=
function
(
model
,
resp
,
options
)
{
model
.
afterSave
(
model
);
if
(
success
)
success
(
model
,
resp
,
options
);
};
Backbone
.
Model
.
prototype
.
save
.
call
(
this
,
attrs
,
options
);
},
afterSave
:
function
(
self
)
{
// remove deleted attrs
if
(
!
_
.
isEmpty
(
self
.
deleteKeys
))
{
// remove the to be deleted keys from the returned model
_
.
each
(
self
.
deleteKeys
,
function
(
key
)
{
self
.
unset
(
key
);
});
// not able to do via backbone since we're not destroying the model
$
.
ajax
({
url
:
self
.
url
,
// json to and fro
contentType
:
"application/json"
,
dataType
:
"json"
,
// delete
type
:
'DELETE'
,
// data
data
:
JSON
.
stringify
({
deleteKeys
:
self
.
deleteKeys
})
})
.
fail
(
function
(
hdr
,
status
,
error
)
{
CMS
.
ServerError
(
self
,
"Deleting keys:"
+
status
);
})
.
done
(
function
(
data
,
status
,
error
)
{
// clear deleteKeys on success
self
.
deleteKeys
=
[];
});
}
}
});
cms/static/js/views/settings/advanced_view.js
View file @
7b3c81ca
...
...
@@ -73,35 +73,15 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
// TODO one last verification scan:
// call validateKey on each to ensure proper format
// check for dupes
var
self
=
this
;
this
.
model
.
save
({},
{
success
:
function
()
{
self
.
render
();
window
.
alert
(
"Saved"
);
},
error
:
CMS
.
ServerError
});
// FIXME don't delete if the validation didn't succeed in the save call
// remove deleted attrs
if
(
!
_
.
isEmpty
(
this
.
model
.
deleteKeys
))
{
var
self
=
this
;
// not able to do via backbone since we're not destroying the model
$
.
ajax
({
url
:
this
.
model
.
url
,
// json to and fro
contentType
:
"application/json"
,
dataType
:
"json"
,
// delete
type
:
'DELETE'
,
// data
data
:
JSON
.
stringify
({
deleteKeys
:
this
.
model
.
deleteKeys
})
})
.
fail
(
function
(
hdr
,
status
,
error
)
{
CMS
.
ServerError
(
self
.
model
,
"Deleting keys:"
+
status
);
})
.
done
(
function
(
data
,
status
,
error
)
{
// clear deleteKeys on success
self
.
model
.
deleteKeys
=
[];
});
}
},
revertView
:
function
(
event
)
{
this
.
model
.
deleteKeys
=
[];
...
...
@@ -149,6 +129,10 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
var
validation
=
this
.
model
.
validate
(
newEntryModel
);
if
(
validation
)
{
console
.
log
(
'reserved key'
);
if
(
_
.
has
(
validation
,
newKey
))
{
// swap to the key which the map knows about
validation
[
oldKey
]
=
validation
[
newKey
];
}
this
.
model
.
trigger
(
"error"
,
this
.
model
,
validation
);
// abandon update
return
;
...
...
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