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
488140bf
Commit
488140bf
authored
Dec 14, 2012
by
Valera Rozuvan
Committed by
Alexander Kryklia
Jan 15, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Work in progress on rewriting GST.
parent
29b42990
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
57 additions
and
71 deletions
+57
-71
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
+57
-71
No files found.
common/lib/xmodule/xmodule/js/src/graphical_slider_tool/state.js
View file @
488140bf
...
...
@@ -83,19 +83,48 @@ define('State', ['logme'], function (logme) {
plotDiv
.
bind
(
'update_plot'
,
callback
);
}
function
getParameterValue
(
const
Name
)
{
function
getParameterValue
(
param
Name
)
{
if
(
constants
.
hasOwnProperty
(
constName
)
===
false
)
{
// If the name of the constant is not tracked by state, return an
// 'undefined' value.
// If the name of the constant is not tracked by state, return an
// 'undefined' value.
if
(
parameters
.
hasOwnProperty
(
paramName
)
===
false
)
{
return
;
}
return
constants
[
constName
]
;
return
parameters
[
paramname
].
value
;
}
function
setConstValue
(
constName
,
constValue
)
{
// ####################################################################
//
// Function: setParameterValue(paramName, paramValue, element)
// --------------------------------------------------
//
// This function can be called from a callback, registered by a slider
// or a text input, when specific events ('slide' or 'change') are
// triggered.
//
// The 'paramName' is the name of the parameter in 'parameters' object
// whose value must be updated to the new value of 'paramValue'.
//
// Before we update the value, we must check that:
//
// 1.) the parameter named as 'paramName' actually exists in the
// 'parameters' object;
// 2.) the value 'paramValue' is a valid floating-point number, and
// it lies within the range specified by the 'min' and 'max'
// properties of the stored parameter object.
//
// If 'paramName' and 'paramValue' turn out to be valid, we will update
// the stored value in the parameter with the new value, and also
// update all of the text inputs and the slider that correspond to this
// parameter (if any), so that they reflect the new parameter's value.
//
// If something went wrong (for example the new value is outside the
// allowed range), then we will reset the 'element' to display the
// original value.
//
// ####################################################################
function
setParameterValue
(
paramName
,
paramValue
,
element
)
{
var
inputDiv
;
if
(
constants
.
hasOwnProperty
(
constName
)
===
false
)
{
...
...
@@ -119,7 +148,7 @@ define('State', ['logme'], function (logme) {
if
(
inputDiv
.
length
!==
0
)
{
inputDiv
.
val
(
constValue
);
}
}
}
// End-of: function setParameterValue
// ####################################################################
//
...
...
@@ -154,28 +183,31 @@ define('State', ['logme'], function (logme) {
//
// ####################################################################
function
processParameter
(
obj
)
{
var
newParamObj
;
var
paramName
,
newParamObj
;
if
(
typeof
obj
[
'@var'
]
!==
'string'
)
{
logme
(
'[ERROR] state.processParameter(obj): obj["'
+
attrName
+
'"] is not a string.'
'[ERROR] State.processParameter(obj): obj["@var"] is not a string.'
,
obj
[
'@var'
],
'---> Not adding a parameter.'
);
return
;
}
paramName
=
obj
[
'@var'
];
newParamObj
=
{};
processString
(
'@var'
,
'name'
);
if
(
(
processFloat
(
'@min'
,
'min'
)
===
false
)
||
(
processFloat
(
'@max'
,
'max'
)
===
false
)
||
(
processFloat
(
'@initial'
,
'value'
)
===
false
)
)
{
logme
(
'---> Not adding a parameter named "'
+
paramName
+
'".'
);
processFloat
(
'@min'
,
'min'
);
processFloat
(
'@max'
,
'max'
);
processFloat
(
'@initial'
,
'value'
);
if
(
checkRequired
(
'name'
,
'min'
,
'max'
,
'value'
)
===
false
)
{
logme
(
'Not creating a parameter.'
);
return
;
}
constants
[
constName
]
=
constValue
;
return
;
...
...
@@ -185,10 +217,11 @@ define('State', ['logme'], function (logme) {
if
(
typeof
obj
[
attrName
]
!==
'string'
)
{
logme
(
'[ERROR] state.processParameter(obj): obj["'
+
attrName
+
'"] is not a string.'
'[ERROR] state.processParameter(obj): obj["'
+
attrName
+
'"] is not a string.'
,
obj
[
attrName
]
);
return
;
return
false
;
}
else
{
attrValue
=
parseFloat
(
obj
[
attrName
]);
...
...
@@ -197,62 +230,15 @@ define('State', ['logme'], function (logme) {
'[ERROR] state.processParameter(obj): for attrName = "'
+
attrName
+
'" attrValue is NaN.'
);
return
;
return
false
;
}
}
newParamObj
[
newAttrName
]
=
paramValue
;
}
function
processString
(
attrName
,
newAttrName
)
{
if
(
typeof
obj
[
attrName
]
!==
'string'
)
{
logme
(
'[ERROR] state.processParameter(obj): obj["'
+
attrName
+
'"] is not a string.'
);
return
;
}
newParamObj
[
newAttrName
]
=
obj
[
attrName
];
}
}
function
addConstFromSlider
(
obj
)
{
var
constName
,
constValue
,
rangeBlobs
;
// The name of the constant is obj['@var']. The value (initial) of
// the constant is the second blob of the 'range' parameter of the
// slider which is obj['@range']. Multiple sliders and/or inputs
// can represent the same constant - therefore 'initial' is in
// brackets. The range is a string composed of 3 blobs, separated
// by commas.
if
(
typeof
obj
[
'@var'
]
===
'undefined'
)
{
return
;
}
constName
=
obj
[
'@var'
];
if
(
typeof
obj
[
'@range'
]
!==
'string'
)
{
constValue
=
0
;
}
else
{
rangeBlobs
=
obj
[
'@range'
].
split
(
','
);
// We must have gotten exactly 3 blobs (pieces) from the split.
if
(
rangeBlobs
.
length
!==
3
)
{
constValue
=
0
;
}
else
{
// Get the second blob from the split string.
constValue
=
parseFloat
(
rangeBlobs
[
1
]);
if
(
isNaN
(
constValue
)
===
true
)
{
constValue
=
0
;
}
}
}
constants
[
constName
]
=
constValue
;
}
return
true
;
}
// End-of: function processFloat
}
// End-of: function processParameter
}
// End-of: function State
});
...
...
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