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
4ae691e8
Commit
4ae691e8
authored
Feb 13, 2013
by
cahrens
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert JSON that doesn't parse to String (unless object, array, or single quote).
parent
f56729db
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
6 deletions
+28
-6
cms/static/js/views/settings/advanced_view.js
+28
-6
No files found.
cms/static/js/views/settings/advanced_view.js
View file @
4ae691e8
...
...
@@ -62,14 +62,36 @@ CMS.Views.Settings.Advanced = CMS.Views.ValidatingView.extend({
},
onBlur
:
function
(
mirror
)
{
var
key
=
$
(
mirror
.
getWrapperElement
()).
closest
(
'.row'
).
children
(
'.key'
).
attr
(
'id'
);
var
quotedValue
=
mirror
.
getValue
();
var
stringValue
=
$
.
trim
(
mirror
.
getValue
());
// update CodeMirror to show the trimmed value.
mirror
.
setValue
(
stringValue
);
var
JSONValue
=
undefined
;
try
{
var
JSONValue
=
JSON
.
parse
(
quotedValue
);
self
.
model
.
set
(
key
,
JSONValue
,
{
validate
:
true
});
JSONValue
=
JSON
.
parse
(
stringValue
);
}
catch
(
e
)
{
// If it didn't parse, try converting non-arrays/non-objects to a String.
// But don't convert single-quote strings, which are most likely errors.
var
firstNonWhite
=
stringValue
.
substring
(
0
,
1
);
if
(
firstNonWhite
!==
"{"
&&
firstNonWhite
!==
"["
&&
firstNonWhite
!==
"'"
)
{
try
{
stringValue
=
'"'
+
stringValue
+
'"'
;
JSONValue
=
JSON
.
parse
(
stringValue
);
mirror
.
setValue
(
stringValue
);
}
catch
(
quotedE
)
{
// TODO: validation error
console
.
log
(
"Error with JSON, even after converting to String."
)
console
.
log
(
quotedE
);
JSONValue
=
undefined
;
}
}
else
{
// TODO: validation error
console
.
log
(
"Error with JSON, but will not convert to String."
)
console
.
log
(
e
);
}
}
catch
(
e
)
{
// TODO: error checking
console
.
log
(
e
);
if
(
JSONValue
!==
undefined
)
{
self
.
model
.
set
(
key
,
JSONValue
,
{
validate
:
true
});
}
}
});
...
...
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