Skip to content

Commit

Permalink
Merge pull request #609 from edx/ammar/ent-2438-enterprise-selection-…
Browse files Browse the repository at this point in the history
…page

Enterprise selection page
  • Loading branch information
muhammad-ammar authored Nov 7, 2019
2 parents 98aef0c + 527027e commit 7c9ff5c
Show file tree
Hide file tree
Showing 14 changed files with 645 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ Change Log
Unreleased
----------

[2.0.14] - 2019-11-07
---------------------

* Add Enterprise selection page to allow a learner to select one of linked enterprises

[2.0.13] - 2019-11-07
---------------------

Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

from __future__ import absolute_import, unicode_literals

__version__ = "2.0.13"
__version__ = "2.0.14"

default_app_config = "enterprise.apps.EnterpriseConfig" # pylint: disable=invalid-name
59 changes: 59 additions & 0 deletions enterprise/forms.py
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
2 changes: 2 additions & 0 deletions enterprise/settings/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ def root(*args):
},
]

REPO_ROOT = root('enterprise')

STATIC_ROOT = root('enterprise/assets')

STATIC_URL = '/enterprise/static/'
Expand Down
2 changes: 1 addition & 1 deletion enterprise/static/enterprise/bundles/main.style.css

Large diffs are not rendered by default.

46 changes: 46 additions & 0 deletions enterprise/static/enterprise/js/enterprise_selection_page.js
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);
1 change: 1 addition & 0 deletions enterprise/static/enterprise/sass/main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@
@import 'partials/views/data_sharing_consent';
@import 'partials/views/course_landing_page';
@import 'partials/views/program_landing_page';
@import 'partials/views/enterprise_select_page';
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;
}
}
}
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 %}
7 changes: 6 additions & 1 deletion enterprise/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf.urls import include, url

from enterprise.constants import COURSE_KEY_URL_PATTERN
from enterprise.views import GrantDataSharingPermissions, RouterView
from enterprise.views import EnterpriseSelectionView, GrantDataSharingPermissions, RouterView

ENTERPRISE_ROUTER = RouterView.as_view()

Expand All @@ -18,6 +18,11 @@
GrantDataSharingPermissions.as_view(),
name='grant_data_sharing_permissions'
),
url(
r'^enterprise/select/active',
EnterpriseSelectionView.as_view(),
name='enterprise_select_active'
),
url(
r'^enterprise/handle_consent_enrollment/(?P<enterprise_uuid>[^/]+)/course/{}/$'.format(
settings.COURSE_ID_PATTERN
Expand Down
Loading

0 comments on commit 7c9ff5c

Please sign in to comment.