Commit 4506d4d0 by Awais Committed by Awais Qureshi

Refactoring JS.

ECOM-6466
parent 449a54ba
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-20 14:01+0500\n"
"POT-Creation-Date: 2017-03-21 12:56+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: apps/api/filters.py
#, python-brace-format
......
......@@ -7,19 +7,23 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-20 14:02+0500\n"
"POT-Creation-Date: 2017-03-21 12:56+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
#: static/js/catalogs-change-form.js
msgid "Preview"
msgstr ""
#: static/js/publisher/change-state.js
msgid "Something went wrong! please try again later."
msgstr ""
#: static/js/publisher/comparing-objects.js
msgid "Hide changes"
msgstr ""
......@@ -32,24 +36,20 @@ msgstr ""
msgid "The image file size cannot exceed 1 MB."
msgstr ""
#: static/js/publisher/publisher.js
#: static/js/publisher/instructors.js static/js/publisher/preview-url.js
msgid "Something went wrong!"
msgstr ""
#: static/js/publisher/publisher.js
msgid "Something went wrong! please try again later."
msgstr ""
#: static/js/publisher/publisher.js
#: static/js/publisher/instructors.js
msgid "File must be smaller than 1 megabyte in size."
msgstr ""
#: static/js/publisher/publisher.js
msgid "Please enter a valid URL."
#: static/js/publisher/preview-url.js
msgid "Save"
msgstr ""
#: static/js/publisher/publisher.js
msgid "Save"
#: static/js/publisher/preview-url.js
msgid "Please enter a valid URL."
msgstr ""
#: static/js/publisher/views/dashboard.js
......
......@@ -7,14 +7,14 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-20 14:01+0500\n"
"POT-Creation-Date: 2017-03-21 12:56+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: apps/api/filters.py
......
......@@ -7,20 +7,26 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-03-20 14:02+0500\n"
"POT-Creation-Date: 2017-03-21 12:56+0500\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Language: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
#: static/js/catalogs-change-form.js
msgid "Preview"
msgstr "Prévïéw Ⱡ'σяєм ιρѕυм #"
#: static/js/publisher/change-state.js
msgid "Something went wrong! please try again later."
msgstr ""
"Söméthïng wént wröng! pléäsé trý ägäïn lätér. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя #"
#: static/js/publisher/comparing-objects.js
msgid "Hide changes"
msgstr "Hïdé çhängés Ⱡ'σяєм ιρѕυм ∂σłσя ѕ#"
......@@ -35,30 +41,24 @@ msgstr ""
"Thé ïmägé fïlé sïzé çännöt éxçééd 1 MB. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя#"
#: static/js/publisher/publisher.js
#: static/js/publisher/instructors.js static/js/publisher/preview-url.js
msgid "Something went wrong!"
msgstr "Söméthïng wént wröng! Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, #"
#: static/js/publisher/publisher.js
msgid "Something went wrong! please try again later."
msgstr ""
"Söméthïng wént wröng! pléäsé trý ägäïn lätér. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя #"
#: static/js/publisher/publisher.js
#: static/js/publisher/instructors.js
msgid "File must be smaller than 1 megabyte in size."
msgstr ""
"Fïlé müst ßé smällér thän 1 mégäßýté ïn sïzé. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, "
"¢σηѕє¢тєтυя #"
#: static/js/publisher/publisher.js
msgid "Please enter a valid URL."
msgstr "Pléäsé éntér ä välïd ÛRL. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕ#"
#: static/js/publisher/publisher.js
#: static/js/publisher/preview-url.js
msgid "Save"
msgstr "Sävé Ⱡ'σяєм ι#"
#: static/js/publisher/preview-url.js
msgid "Please enter a valid URL."
msgstr "Pléäsé éntér ä välïd ÛRL. Ⱡ'σяєм ιρѕυм ∂σłσя ѕιт αмєт, ¢σηѕ#"
#: static/js/publisher/views/dashboard.js
msgid ""
"You have successfully created a studio instance ({studioLinkTag}) for "
......
$(document).ready(function(){
$("#change-admin").click(function (e) {
e.preventDefault();
$(".field-admin-name").hide();
$("#field-team-admin").show();
});
});
$(document).ready(function(){
$('.btn-change-state, .btn-publish').click(function (e) {
$.ajax({
type: "PATCH",
url: $(this).data('change-state-url'),
data: JSON.stringify({name: $(this).data('state-name')}),
contentType: "application/json",
success: function (response) {
location.reload();
},
error: function (response) {
if (response.responseJSON) {
$('#stateChangeError').html(response.responseJSON.name);
} else {
$('#stateChangeError').html(gettext('Something went wrong! please try again later.'));
}
$('#stateChangeAlert').show();
console.log(response);
}
});
});
});
$('.remove-image').click(function (e) {
e.preventDefault();
$('.course-image-input').removeClass('hidden');
$('.course-image-thumbnail').hide();
$('.course-image-field a').hide();
$('input#image-clear_id').prop('checked', true);
});
// If file selected mark checkbox unchecked otherwise checked.
$('input#id_image').change(function (e) {
var clearImageInput = $('input#image-clear_id');
e.preventDefault();
if (this.files && this.files[0]) {
clearImageInput.prop('checked', false);
} else {
clearImageInput.prop('checked', true);
}
});
$(document).ready(function(){
$("#id_staff").find('option:selected').each(function(){
var id = this.value,
label = $.parseHTML(this.label),
image_source = $(label[0]).attr('src'),
name = $(label[1]).text();
renderSelectedInstructor(id, name, image_source);
});
$('#add-new-instructor').click(function(e){
$('#addInstructorModal').show();
$('body').addClass('stopScroll');
});
$('#add-instructor-btn').click(function (e) {
$.ajax({
type: "POST",
url: $(this).data('url'),
data: {
'data': JSON.stringify(
{
'given_name': $('#given-name').val(),
'family_name': $('#family-name').val(),
'bio': $('#bio').val(),
'profile_image': $('.select-image').attr('src'),
'position':{
'title': $('#title').val(),
'organization': parseInt($('#id_organization').val())
},
'works': $('#majorWorks').val().split('\n'),
'urls': {
'facebook': $('#facebook').val(),
'twitter': $('#twitter').val(),
'blog': $('#blog').val()
}
}
)
},
success: function (response) {
$('#given-name').val('');
$('#family-name').val('');
$('#title').val('');
$('#bio').val('');
$('.select-image').attr('src', '');
$('#majorWorks').val('');
$('#facebook').val('');
$('#twitter').val('');
$('#blog').val('');
clearModalError();
closeModal(e, $('#addInstructorModal'));
loadInstructor(response['uuid'])
},
error: function (response) {
addModalError(gettext("Something went wrong!"));
console.log(response);
}
});
});
});
function loadSelectedImage(input) {
// 1mb in bytes
var maxFileSize = 1000000;
if (input.files && input.files[0]) {
if (input.files[0].size > maxFileSize) {
addModalError(gettext("File must be smaller than 1 megabyte in size."));
} else {
var reader = new FileReader();
clearModalError();
reader.onload = function (e) {
$('.select-image').attr('src', e.target.result);
};
reader.readAsDataURL(input.files[0]);
}
}
}
$(document).on('change', '#id_staff', function (e) {
var $instructorSelector = $('.instructor-select'),
$instructor = $instructorSelector.find('.select2-selection__choice'),
id = $instructor.find('.instructor-option').last().prop("id"),
image_source,
name;
$instructorSelector.find('.select2-selection__clear').remove();
image_source = $instructor.find('img').last().attr('src');
name = $instructor.find('b').last().text();
renderSelectedInstructor(id, name, image_source);
$instructor.remove();
});
$(document).on('click', '.selected-instructor a', function (e) {
e.preventDefault();
var id = this.id,
option = $('#id_staff').find('option[value="' + id + '"]');
option.prop("selected", false);
this.closest('.selected-instructor, .instructor').remove();
});
function renderSelectedInstructor(id, name, image) {
var instructorHtml = '<div class="instructor"><div><img src="' + image + '"></div><div><a id="' + id + '" ' +
'href="#"><i class="fa fa-trash-o fa-fw"></i></a><b>' + name + '</b></div></div>';
$('.selected-instructor').append(instructorHtml);
}
$(document).on('click', '.btn-save-preview-url', function (e) {
preview_url = $('#id-review-url').val();
if (!preview_url) {
showInvalidPreviewUrlError();
return
}
$.ajax({
type: "PATCH",
url: $(this).data('url'),
data: JSON.stringify({'preview_url': preview_url}),
contentType: "application/json",
success: function (response) {
location.reload();
},
error: function (response) {
showInvalidPreviewUrlError();
}
});
});
function loadInstructor(uuid) {
var url = $('#id_staff').attr('data-autocomplete-light-url') + '?q=' + uuid,
instructor,
id,
label,
image_source,
name;
$.getJSON({
url: url,
success: function (data) {
if (data['results'].length) {
// with uuid there will be only one instructor
instructor = data['results'][0];
id = instructor.id;
label = $.parseHTML(instructor.text);
image_source = $(label).find('img').attr('src');
name = $(label).find('b').text();
$('#id_staff').append($("<option/>", {
value: id,
text: name
}).attr('selected', 'selected'));
renderSelectedInstructor(id, name, image_source);
}
}
});
}
$(document).ready(function(){
$(document).click(function(e){
var modal = $('.modal');
if (event.target == modal[0]) {
closeModal(e, modal);
}
});
$('.closeModal').click(function (e) {
closeModal(e, $('.modal'));
});
$('.btn-course-edit').click(function(e){
$('#editWarningModal').show();
$('body').addClass('stopScroll');
});
$('.btn-preview-accept').click(function(e){
$('#acceptPreviewModal').show();
$('body').addClass('stopScroll');
});
});
function closeModal(event, modal) {
event.preventDefault();
modal.hide();
$('body').removeClass('stopScroll');
}
function addModalError(errorMessage) {
var errorHtml = '<div class="alert alert-error" role="alert" aria-labelledby="alert-title-error" tabindex="-1">' +
'<div><p class="alert-copy">' + errorMessage + '</p></div></div>';
$('#modal-errors').html(errorHtml);
$('#modal-errors').show();
}
function clearModalError($modal) {
$('#modal-errors').html('');
$('#modal-errors').hide();
}
$(document).ready(function(){
$('.btn-accept').click(function (e) {
$.ajax({
type: "PATCH",
url: $(this).data('url'),
data: JSON.stringify({preview_accepted: true}),
contentType: "application/json",
success: function (response) {
location.reload();
},
error: function (response) {
addModalError(gettext("Something went wrong!"));
console.log(response);
}
});
});
});
$(document).on('click', '.btn-edit-preview-url', function (e) {
var $previewUrl = $('.preview-url'),
currentUrl = $previewUrl.find('a').attr('href'),
html = '<input id="id-review-url" type="text" value=' + currentUrl + '>';
$(this).addClass('btn-save-preview-url').removeClass('btn-edit-preview-url');
$(this).text(gettext("Save"));
$('.preview-status').remove();
$previewUrl.html(html);
$('#id-review-url').focus();
});
$('.btn-preview-decline').click(function (e) {
$('#decline-comment').toggle();
});
$(document).on('click', '.btn-save-preview-url', function (e) {
preview_url = $('#id-review-url').val();
if (!preview_url) {
showInvalidPreviewUrlError();
return
}
$.ajax({
type: "PATCH",
url: $(this).data('url'),
data: JSON.stringify({'preview_url': preview_url}),
contentType: "application/json",
success: function (response) {
location.reload();
},
error: function (response) {
showInvalidPreviewUrlError();
}
});
});
function showInvalidPreviewUrlError() {
$('#id-review-url').addClass('has-error');
$('.error-message').html(gettext("Please enter a valid URL."));
}
$(document).ready(function () {
var microMaster = $('#id_is_micromasters'),
xseries = $('#id_is_xseries');
if (microMaster.is(':checked')) {
toggleMicroMaster(true);
}
if (xseries.is(':checked')) {
toggleXseries(true);
}
microMaster.click(function () {
toggleMicroMaster(this.checked);
});
xseries.click(function (e) {
toggleXseries(this.checked)
});
});
function toggleMicroMaster (checked) {
// If is-micromaster checkbox value true from db then show the x-micromaster block.
$('#micromasters_name_group').toggle(checked);
}
function toggleXseries(checked) {
// If is-xseries checkbox value true from db then show the x-series block.
$('#xseries_name_group').toggle(checked);
}
$(document).on('change', '#id_select_revisions', function (e) {
var revisionUrl = $(this.selectedOptions).data('revisionUrl');
// on changing the revision from dropdown set the href of button.
$('#id_open_revision').prop("href", this.value);
if (revisionUrl) {
loadRevisionHistory(revisionUrl);
} else {
$('.show-diff').hide();
$('.current').show();
}
});
function loadRevisionHistory(revisionUrl) {
$.getJSON({
url: revisionUrl,
success: function (data) {
$.each(data, function(key, value) {
var currentObject = $('.history-field-container').find('.' + key);
if (currentObject.length) {
showDiffCourseDetails(value, currentObject.text(), currentObject.siblings('.show-diff'));
currentObject.hide();
}
});
}
});
}
$(function () {
var show_verified_fields,
hide_verified_fields,
show_professional_fields,
hide_professional_fields,
hide_all_fields,
change_fields;
show_verified_fields= function () {
$('#id_price').prop("readonly", false);
};
hide_verified_fields = function () {
$('#id_price').prop("readonly", true).val('0.00');
};
show_professional_fields = function () {
$('#id_price').prop("readonly", false);
};
hide_professional_fields = function () {
$('#id_price').prop("readonly", true).val('0.00');
};
hide_all_fields = function () {
hide_verified_fields();
hide_professional_fields();
};
change_fields = function (select_tag) {
if (!select_tag) {
select_tag = '#id_type';
}
var selected_value = $(select_tag).find("option:selected").val();
if (selected_value === 'verified') {
hide_all_fields();
show_verified_fields();
}
else if (selected_value === 'professional' || selected_value === 'no-id-professional') {
hide_all_fields();
show_professional_fields();
}
else {
hide_all_fields();
}
};
$('#id_type').change(function () {
change_fields(this);
});
$(document).on('change', '#id_type', function (e) {
var $seatBlock = $("#SeatPriceBlock"),
selectedSeatType = this.value;
if (selectedSeatType === 'audit' || selectedSeatType === '') {
$seatBlock.hide();
} else{
$seatBlock.show();
}
});
......@@ -240,8 +240,8 @@
{% endblock %}
{% block extra_js %}
<script src="{% static 'js/publisher/publisher.js' %}"></script>
<script src="{% static 'js/publisher/organizations.js' %}"></script>
<script src="{% static 'js/publisher/course-tabs.js' %}"></script>
<script src="{% static 'js/publisher/seat-type-change.js' %}"></script>
<script src="{% static 'js/publisher/change-admin.js' %}"></script>
{% endblock %}
......@@ -657,11 +657,14 @@
{% endblock %}
{% block extra_js %}
<script src="{% static 'js/publisher/publisher.js' %}"></script>
<script src="{% static 'js/publisher/course-tabs.js' %}"></script>
<script src="{% static 'js/publisher/organizations.js' %}"></script>
<script src="{% static 'js/publisher/instructors.js' %}"></script>
<script src="{% static 'js/publisher/seat-type-change.js' %}"></script>
<script src="{% static 'js/publisher/image-validation.js' %}"></script>
<script src="{% static 'js/publisher/program-types.js' %}"></script>
<script src="{% static 'js/publisher/modal-screen.js' %}"></script>
<script src="{% static 'js/publisher/course-image.js' %}"></script>
{% endblock %}
{% block js_without_compress %}
......
......@@ -167,9 +167,11 @@
{% block extra_js %}
<script src="{% static 'bower_components/google-diff-match-patch/diff_match_patch.js' %}"></script>
<script src="{% static 'js/publisher/views/course_detail.js' %}"></script>
<script src="{% static 'js/publisher/publisher.js' %}"></script>
<script src="{% static 'js/publisher/organizations.js' %}"></script>
<script src="{% static 'js/publisher/comparing-objects.js' %}"></script>
<script src="{% static 'js/publisher/jquery-dateFormat.min.js' %}"></script>
<script src="{% static 'js/publisher/comments.js' %}"></script>
<script src="{% static 'js/publisher/change-state.js' %}"></script>
<script src="{% static 'js/publisher/revision-history.js' %}"></script>
<script src="{% static 'js/publisher/modal-screen.js' %}"></script>
{% endblock %}
......@@ -402,8 +402,8 @@
{% endblock %}
{% block extra_js %}
<script src="{% static 'js/publisher/publisher.js' %}"></script>
<script src="{% static 'js/publisher/course-tabs.js' %}"></script>
<script src="{% static 'js/publisher/organizations.js' %}"></script>
<script src="{% static 'js/publisher/image-validation.js' %}"></script>
<script src="{% static 'js/publisher/course-image.js' %}"></script>
{% endblock %}
......@@ -93,10 +93,12 @@
<script src="{% static 'bower_components/clipboard/dist/clipboard.min.js' %}"></script>
<script src="{% static 'js/publisher/jquery-dateFormat.min.js' %}"></script>
<script src="{% static 'js/publisher/views/course_detail.js' %}"></script>
<script src="{% static 'js/publisher/publisher.js' %}"></script>
<script src="{% static 'js/publisher/organizations.js' %}"></script>
<script src="{% static 'js/publisher/comments.js' %}"></script>
<script src="{% static 'js/publisher/course-tabs.js' %}"></script>
<script src="{% static 'js/publisher/preview-url.js' %}"></script>
<script src="{% static 'js/publisher/change-state.js' %}"></script>
<script src="{% static 'js/publisher/modal-screen.js' %}"></script>
<script>
new Clipboard(".btn-copy", {
text: function(trigger) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment