-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #609 from edx/ammar/ent-2438-enterprise-selection-…
…page Enterprise selection page
- Loading branch information
Showing
14 changed files
with
645 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
User-facing forms for the Enterprise app. | ||
""" | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
from django import forms | ||
from django.urls import Resolver404, resolve | ||
from django.utils.translation import ugettext as _ | ||
|
||
from enterprise.models import EnterpriseCustomer, EnterpriseCustomerUser | ||
|
||
ENTERPRISE_SELECT_SUBTITLE = _( | ||
u'You have access to multiple organizations. Select the organization that you will use ' | ||
'to sign up for courses. If you want to change organizations, sign out and sign back in.' | ||
) | ||
|
||
|
||
class EnterpriseSelectionForm(forms.Form): | ||
""" | ||
Enterprise Selection Form. | ||
""" | ||
|
||
enterprise = forms.ChoiceField(choices=(), label='Organization') | ||
success_url = forms.CharField(widget=forms.HiddenInput(), required=False) | ||
|
||
def __init__(self, *args, **kwargs): | ||
""" | ||
Initialize form. | ||
""" | ||
super(EnterpriseSelectionForm, self).__init__(*args, **kwargs) | ||
initial = kwargs['initial'] | ||
self._user_id = kwargs['initial'].pop('user_id') | ||
self.fields['enterprise'].choices = initial['enterprises'] | ||
self.fields['success_url'].initial = initial['success_url'] | ||
|
||
def clean(self): | ||
""" | ||
Validate POST data. | ||
""" | ||
cleaned_data = super(EnterpriseSelectionForm, self).clean() | ||
enterprise = cleaned_data.get('enterprise') | ||
|
||
try: | ||
EnterpriseCustomer.objects.get(uuid=enterprise) # pylint: disable=no-member | ||
except EnterpriseCustomer.DoesNotExist: | ||
raise forms.ValidationError(_("Enterprise not found")) | ||
|
||
# verify that learner is really a member of selected enterprise | ||
if not EnterpriseCustomerUser.objects.filter(enterprise_customer=enterprise, user_id=self._user_id).exists(): | ||
raise forms.ValidationError(_("Wrong Enterprise")) | ||
|
||
try: | ||
# validate if path is a valid | ||
resolve(cleaned_data['success_url']) | ||
except Resolver404: | ||
raise forms.ValidationError(_("Incorrect success url")) | ||
|
||
return cleaned_data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
46 changes: 46 additions & 0 deletions
46
enterprise/static/enterprise/js/enterprise_selection_page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
function redirectToURL(redirectURL) { | ||
location.href = redirectURL; | ||
} | ||
|
||
function setupFormSubmit() { | ||
$('#select-enterprise-form').submit(function(event){ | ||
event.preventDefault(); | ||
var selectedEnterpriseUUID = $("#id_enterprise").val(); | ||
var successURL = $("#id_success_url").val(); | ||
|
||
$("#activate-progress-icon").removeClass("is-hidden"); | ||
$("#select-enterprise-submit").attr("disabled", true); | ||
|
||
$.ajax({ | ||
url : "/enterprise/select/active", | ||
method : "POST", | ||
beforeSend: function (xhr) { | ||
xhr.setRequestHeader("X-CSRFToken", $.cookie("csrftoken")); | ||
}, | ||
data : { | ||
enterprise : selectedEnterpriseUUID, | ||
success_url: successURL | ||
}, | ||
|
||
success: function(xhr) { | ||
redirectToURL(xhr.success_url); | ||
}, | ||
|
||
error : function(xhr) { | ||
$("#activate-progress-icon").addClass("is-hidden"); | ||
$("#select-enterprise-submit").attr("disabled", false); | ||
$("#select-enterprise-form-error") | ||
.text(xhr.responseJSON.errors.join(", ")) | ||
.removeClass( "is-hidden" ); | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
(function() { | ||
"use strict"; | ||
|
||
$(document).ready(function() { | ||
setupFormSubmit(); | ||
}); | ||
}).call(this); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
enterprise/static/enterprise/sass/partials/views/_enterprise_select_page.scss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
.select-enterprise-container { | ||
width: auto; | ||
max-width: 600px; | ||
min-width: 300px; | ||
margin: 0 auto; | ||
|
||
* { | ||
font-size: 16px; | ||
} | ||
|
||
p { | ||
margin-bottom: 15px; | ||
} | ||
|
||
.select-enterprise-title { | ||
font-size: 20px !important; | ||
color: $blue !important; | ||
font-weight: normal; | ||
margin-bottom: 10px; | ||
} | ||
|
||
label { | ||
margin-right: 10px; | ||
} | ||
|
||
select { | ||
width: 60%; | ||
max-width: 350px; | ||
background-color: white; | ||
color: #333; | ||
box-sizing: border-box; | ||
margin-bottom: 10px; | ||
border-radius: 5px; | ||
font-size: large; | ||
} | ||
|
||
.select-enterprise.errorlist { | ||
display: list-item; | ||
color: rgb(203, 7, 18); | ||
margin-left: 40px; | ||
margin-bottom: 20px; | ||
} | ||
|
||
.is-hidden { | ||
display: none !important; | ||
} | ||
|
||
button.select-enterprise-submit-button { | ||
border-color: transparent; | ||
height: auto; | ||
max-width: 180px; | ||
min-width: 125px; | ||
border-radius: 5px; | ||
font-size: 16px; | ||
font-weight: bold; | ||
background: #0075B4; | ||
border: none; | ||
color: #fff; | ||
margin-right: 10px; | ||
padding: 10px 15px; | ||
box-shadow: none; | ||
width: auto; | ||
|
||
&:hover { | ||
cursor: pointer; | ||
background: #0b5177; | ||
} | ||
|
||
&:focus { | ||
background-color: #065683; | ||
} | ||
|
||
&:active { | ||
background-color: #0075B4; | ||
} | ||
|
||
&:disabled { | ||
background-color: #a0a0a0; | ||
color: #d9d9d9; | ||
} | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
enterprise/templates/enterprise/enterprise_customer_select_form.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
|
||
{% extends 'enterprise/base.html' %} | ||
|
||
{% load i18n staticfiles enterprise %} | ||
|
||
{% block extrahead %} | ||
<script type="text/javascript" src="{% static 'js/vendor/jquery.cookie.js' %}"></script> | ||
<script type="text/javascript" src="{% static 'enterprise/js/enterprise_selection_page.js' %}"></script> | ||
{% endblock %} | ||
|
||
{% block contents %} | ||
<main> | ||
<div class="enterprise-container"> | ||
<div class="select-enterprise-container"> | ||
|
||
<h2 class="select-enterprise-title">{{ select_enterprise_message_title|safe }}</h2> | ||
<div class="select-enterprise-message"> | ||
<p>{{ select_enterprise_message_subtitle|safe }}</p> | ||
</div> | ||
|
||
<form action="" method="POST" id="select-enterprise-form"> | ||
{% csrf_token %} | ||
|
||
<div | ||
role="alert" | ||
aria-live="assertive" | ||
class="select-enterprise errorlist is-hidden" | ||
id="select-enterprise-form-error"> | ||
</div> | ||
|
||
{% for field in form.visible_fields %} | ||
<div> | ||
{{ field.label_tag }} | ||
{{ field.errors }} | ||
{{ field }} | ||
{{ field.help_text }} | ||
</div> | ||
{% endfor %} | ||
|
||
{% for hidden_field in form.hidden_fields %} | ||
<div> | ||
{{ hidden_field.errors }} | ||
{{ hidden_field }} | ||
</div> | ||
{% endfor %} | ||
|
||
<button | ||
type="submit" | ||
class="background-input select-enterprise-submit-button" | ||
id="select-enterprise-submit"> | ||
{% trans "Continue" %} | ||
</button> | ||
<span id="activate-progress-icon" class="icon fa fa-spinner fa-spin is-hidden" aria-hidden="true"></span> | ||
</form> | ||
|
||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.