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
24869016
Commit
24869016
authored
Nov 13, 2014
by
stephensanchez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adding disable logic for buttons.
Update tests, clean up approach. Updating jasmine tests.
parent
d0c06dda
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
49 additions
and
0 deletions
+49
-0
lms/static/js/spec/student_account/login_spec.js
+10
-0
lms/static/js/spec/student_account/register_spec.js
+8
-0
lms/static/js/student_account/views/FormView.js
+21
-0
lms/static/js/student_account/views/LoginView.js
+4
-0
lms/static/js/student_account/views/PasswordResetView.js
+3
-0
lms/static/js/student_account/views/RegisterView.js
+3
-0
No files found.
lms/static/js/spec/student_account/login_spec.js
View file @
24869016
...
@@ -134,6 +134,9 @@ define([
...
@@ -134,6 +134,9 @@ define([
// Submit the form, with successful validation
// Submit the form, with successful validation
submitForm
(
true
);
submitForm
(
true
);
// Form button should be disabled on success.
expect
(
view
.
$submitButton
).
toHaveAttr
(
'disabled'
);
// Verify that the client contacts the server with the expected data
// Verify that the client contacts the server with the expected data
AjaxHelpers
.
expectRequest
(
AjaxHelpers
.
expectRequest
(
requests
,
'POST'
,
requests
,
'POST'
,
...
@@ -213,6 +216,8 @@ define([
...
@@ -213,6 +216,8 @@ define([
// Expect auth complete NOT to have been triggered
// Expect auth complete NOT to have been triggered
expect
(
authComplete
).
toBe
(
false
);
expect
(
authComplete
).
toBe
(
false
);
// Form button should be re-enabled when errors occur
expect
(
view
.
$submitButton
).
not
.
toHaveAttr
(
'disabled'
);
});
});
it
(
'displays an error if the server returns an error while logging in'
,
function
()
{
it
(
'displays an error if the server returns an error while logging in'
,
function
()
{
...
@@ -227,10 +232,15 @@ define([
...
@@ -227,10 +232,15 @@ define([
// Expect that an error is displayed and that auth complete is not triggered
// Expect that an error is displayed and that auth complete is not triggered
expect
(
view
.
$errors
).
not
.
toHaveClass
(
'hidden'
);
expect
(
view
.
$errors
).
not
.
toHaveClass
(
'hidden'
);
expect
(
authComplete
).
toBe
(
false
);
expect
(
authComplete
).
toBe
(
false
);
// Form button should be re-enabled on server failure.
expect
(
view
.
$submitButton
).
not
.
toHaveAttr
(
'disabled'
);
// If we try again and succeed, the error should go away
// If we try again and succeed, the error should go away
submitForm
();
submitForm
();
// Form button should be disabled on success.
expect
(
view
.
$submitButton
).
toHaveAttr
(
'disabled'
);
// This time, respond with status code 200
// This time, respond with status code 200
AjaxHelpers
.
respondWithJson
(
requests
,
{});
AjaxHelpers
.
respondWithJson
(
requests
,
{});
...
...
lms/static/js/spec/student_account/register_spec.js
View file @
24869016
...
@@ -242,6 +242,8 @@ define([
...
@@ -242,6 +242,8 @@ define([
// Verify that auth complete is triggered
// Verify that auth complete is triggered
expect
(
authComplete
).
toBe
(
true
);
expect
(
authComplete
).
toBe
(
true
);
// Form button should be disabled on success.
expect
(
view
.
$submitButton
).
toHaveAttr
(
'disabled'
);
});
});
it
(
'sends analytics info containing the enrolled course ID'
,
function
()
{
it
(
'sends analytics info containing the enrolled course ID'
,
function
()
{
...
@@ -295,6 +297,8 @@ define([
...
@@ -295,6 +297,8 @@ define([
// Verify that no submission errors are visible
// Verify that no submission errors are visible
expect
(
view
.
$errors
).
toHaveClass
(
'hidden'
);
expect
(
view
.
$errors
).
toHaveClass
(
'hidden'
);
// Form button should be disabled on success.
expect
(
view
.
$submitButton
).
toHaveAttr
(
'disabled'
);
});
});
it
(
'displays registration form validation errors'
,
function
()
{
it
(
'displays registration form validation errors'
,
function
()
{
...
@@ -308,6 +312,8 @@ define([
...
@@ -308,6 +312,8 @@ define([
// Expect that auth complete is NOT triggered
// Expect that auth complete is NOT triggered
expect
(
authComplete
).
toBe
(
false
);
expect
(
authComplete
).
toBe
(
false
);
// Form button should be re-enabled on error.
expect
(
view
.
$submitButton
).
not
.
toHaveAttr
(
'disabled'
);
});
});
it
(
'displays an error if the server returns an error while registering'
,
function
()
{
it
(
'displays an error if the server returns an error while registering'
,
function
()
{
...
@@ -332,6 +338,8 @@ define([
...
@@ -332,6 +338,8 @@ define([
// Expect that the error is hidden and that auth complete is triggered
// Expect that the error is hidden and that auth complete is triggered
expect
(
view
.
$errors
).
toHaveClass
(
'hidden'
);
expect
(
view
.
$errors
).
toHaveClass
(
'hidden'
);
expect
(
authComplete
).
toBe
(
true
);
expect
(
authComplete
).
toBe
(
true
);
// Form button should be disabled on success.
expect
(
view
.
$submitButton
).
toHaveAttr
(
'disabled'
);
});
});
});
});
});
});
lms/static/js/student_account/views/FormView.js
View file @
24869016
...
@@ -28,6 +28,8 @@ var edx = edx || {};
...
@@ -28,6 +28,8 @@ var edx = edx || {};
// String to append to required label fields
// String to append to required label fields
requiredStr
:
'*'
,
requiredStr
:
'*'
,
submitButton
:
''
,
initialize
:
function
(
data
)
{
initialize
:
function
(
data
)
{
this
.
model
=
data
.
model
;
this
.
model
=
data
.
model
;
this
.
preRender
(
data
);
this
.
preRender
(
data
);
...
@@ -65,6 +67,7 @@ var edx = edx || {};
...
@@ -65,6 +67,7 @@ var edx = edx || {};
this
.
$form
=
$container
.
find
(
'form'
);
this
.
$form
=
$container
.
find
(
'form'
);
this
.
$errors
=
$container
.
find
(
'.submission-error'
);
this
.
$errors
=
$container
.
find
(
'.submission-error'
);
this
.
$submitButton
=
$container
.
find
(
this
.
submitButton
);
},
},
buildForm
:
function
(
data
)
{
buildForm
:
function
(
data
)
{
...
@@ -178,6 +181,7 @@ var edx = edx || {};
...
@@ -178,6 +181,7 @@ var edx = edx || {};
saveError
:
function
(
error
)
{
saveError
:
function
(
error
)
{
this
.
errors
=
[
'<li>'
+
error
.
responseText
+
'</li>'
];
this
.
errors
=
[
'<li>'
+
error
.
responseText
+
'</li>'
];
this
.
setErrors
();
this
.
setErrors
();
this
.
toggleDisableButton
(
false
);
},
},
setErrors
:
function
()
{
setErrors
:
function
()
{
...
@@ -209,6 +213,8 @@ var edx = edx || {};
...
@@ -209,6 +213,8 @@ var edx = edx || {};
event
.
preventDefault
();
event
.
preventDefault
();
this
.
toggleDisableButton
(
true
);
if
(
!
_
.
compact
(
this
.
errors
).
length
)
{
if
(
!
_
.
compact
(
this
.
errors
).
length
)
{
this
.
model
.
set
(
data
);
this
.
model
.
set
(
data
);
this
.
model
.
save
();
this
.
model
.
save
();
...
@@ -221,11 +227,26 @@ var edx = edx || {};
...
@@ -221,11 +227,26 @@ var edx = edx || {};
toggleErrorMsg
:
function
(
show
)
{
toggleErrorMsg
:
function
(
show
)
{
if
(
show
)
{
if
(
show
)
{
this
.
setErrors
();
this
.
setErrors
();
this
.
toggleDisableButton
(
false
);
}
else
{
}
else
{
this
.
element
.
hide
(
this
.
$errors
);
this
.
element
.
hide
(
this
.
$errors
);
}
}
},
},
/**
* If a form button is defined for this form, this will disable the button on
* submit, and re-enable the button if an error occurs.
*
* Args:
* disabled (boolean): If set to TRUE, disable the button.
*
*/
toggleDisableButton
:
function
(
disabled
)
{
if
(
this
.
$submitButton
)
{
this
.
$submitButton
.
attr
(
'disabled'
,
disabled
);
}
},
validate
:
function
(
$el
)
{
validate
:
function
(
$el
)
{
return
edx
.
utils
.
validate
(
$el
);
return
edx
.
utils
.
validate
(
$el
);
}
}
...
...
lms/static/js/student_account/views/LoginView.js
View file @
24869016
...
@@ -21,6 +21,8 @@ var edx = edx || {};
...
@@ -21,6 +21,8 @@ var edx = edx || {};
requiredStr
:
''
,
requiredStr
:
''
,
submitButton
:
'.js-login'
,
preRender
:
function
(
data
)
{
preRender
:
function
(
data
)
{
this
.
providers
=
data
.
thirdPartyAuth
.
providers
||
[];
this
.
providers
=
data
.
thirdPartyAuth
.
providers
||
[];
this
.
currentProvider
=
data
.
thirdPartyAuth
.
currentProvider
||
''
;
this
.
currentProvider
=
data
.
thirdPartyAuth
.
currentProvider
||
''
;
...
@@ -54,6 +56,7 @@ var edx = edx || {};
...
@@ -54,6 +56,7 @@ var edx = edx || {};
this
.
$form
=
this
.
$container
.
find
(
'form'
);
this
.
$form
=
this
.
$container
.
find
(
'form'
);
this
.
$errors
=
this
.
$container
.
find
(
'.submission-error'
);
this
.
$errors
=
this
.
$container
.
find
(
'.submission-error'
);
this
.
$authError
=
this
.
$container
.
find
(
'.already-authenticated-msg'
);
this
.
$authError
=
this
.
$container
.
find
(
'.already-authenticated-msg'
);
this
.
$submitButton
=
this
.
$container
.
find
(
this
.
submitButton
);
/* If we're already authenticated with a third-party
/* If we're already authenticated with a third-party
* provider, try logging in. The easiest way to do this
* provider, try logging in. The easiest way to do this
...
@@ -101,6 +104,7 @@ var edx = edx || {};
...
@@ -101,6 +104,7 @@ var edx = edx || {};
this
.
element
.
hide
(
this
.
$authError
);
this
.
element
.
hide
(
this
.
$authError
);
this
.
element
.
show
(
this
.
$errors
);
this
.
element
.
show
(
this
.
$errors
);
}
}
this
.
toggleDisableButton
(
false
);
}
}
});
});
})(
jQuery
,
_
,
gettext
);
})(
jQuery
,
_
,
gettext
);
lms/static/js/student_account/views/PasswordResetView.js
View file @
24869016
...
@@ -19,6 +19,8 @@ var edx = edx || {};
...
@@ -19,6 +19,8 @@ var edx = edx || {};
requiredStr
:
''
,
requiredStr
:
''
,
submitButton
:
'.js-reset'
,
preRender
:
function
(
data
)
{
preRender
:
function
(
data
)
{
this
.
listenTo
(
this
.
model
,
'sync'
,
this
.
saveSuccess
);
this
.
listenTo
(
this
.
model
,
'sync'
,
this
.
saveSuccess
);
},
},
...
@@ -26,6 +28,7 @@ var edx = edx || {};
...
@@ -26,6 +28,7 @@ var edx = edx || {};
toggleErrorMsg
:
function
(
show
)
{
toggleErrorMsg
:
function
(
show
)
{
if
(
show
)
{
if
(
show
)
{
this
.
setErrors
();
this
.
setErrors
();
this
.
toggleDisableButton
(
false
)
}
else
{
}
else
{
this
.
element
.
hide
(
this
.
$errors
);
this
.
element
.
hide
(
this
.
$errors
);
}
}
...
...
lms/static/js/student_account/views/RegisterView.js
View file @
24869016
...
@@ -18,6 +18,8 @@ var edx = edx || {};
...
@@ -18,6 +18,8 @@ var edx = edx || {};
formType
:
'register'
,
formType
:
'register'
,
submitButton
:
'.js-register'
,
preRender
:
function
(
data
)
{
preRender
:
function
(
data
)
{
this
.
providers
=
data
.
thirdPartyAuth
.
providers
||
[];
this
.
providers
=
data
.
thirdPartyAuth
.
providers
||
[];
this
.
currentProvider
=
data
.
thirdPartyAuth
.
currentProvider
||
''
;
this
.
currentProvider
=
data
.
thirdPartyAuth
.
currentProvider
||
''
;
...
@@ -57,5 +59,6 @@ var edx = edx || {};
...
@@ -57,5 +59,6 @@ var edx = edx || {};
saveSuccess
:
function
()
{
saveSuccess
:
function
()
{
this
.
trigger
(
'auth-complete'
);
this
.
trigger
(
'auth-complete'
);
}
}
});
});
})(
jQuery
,
_
,
gettext
);
})(
jQuery
,
_
,
gettext
);
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