diff --git a/dashboard-ui/scripts/userparentalcontrol.js b/dashboard-ui/scripts/userparentalcontrol.js index a2bd1e3e49..6c75a13ba2 100644 --- a/dashboard-ui/scripts/userparentalcontrol.js +++ b/dashboard-ui/scripts/userparentalcontrol.js @@ -1,4 +1,4 @@ -define(['jQuery', 'listViewStyle', 'paper-icon-button-light'], function ($) { +define(['jQuery', 'datetime', 'listViewStyle', 'paper-icon-button-light'], function ($, datetime) { function populateRatings(allParentalRatings, page) { @@ -55,9 +55,9 @@ var html = ''; - html += '

' + Globalize.translate('HeaderBlockItemsWithNoRating') + '

'; + html += '

' + Globalize.translate('HeaderBlockItemsWithNoRating') + '

'; - html += '
'; + html += '
'; for (var i = 0, length = items.length; i < length; i++) { @@ -65,7 +65,7 @@ var checkedAttribute = user.Policy.BlockUnratedItems.indexOf(item.value) != -1 ? ' checked="checked"' : ''; - html += '' + item.name + ''; + html += ''; } html += '
'; @@ -116,13 +116,13 @@ var li = '
'; li += '
'; - li += '

'; + li += '

'; li += h; li += '

'; li += '
'; li += ''; - + li += '
'; return li; @@ -156,24 +156,25 @@ function renderAccessSchedule(page, schedules) { - var html = '
'; index++; @@ -181,11 +182,10 @@ }).join(''); - html += ''; + var accessScheduleList = page.querySelector('.accessScheduleList'); + accessScheduleList.innerHTML = html; - var elem = $('.accessScheduleList', page).html(html).trigger('create'); - - $('.btnDelete', elem).on('click', function () { + $('.btnDelete', accessScheduleList).on('click', function () { deleteAccessSchedule(page, schedules, parseInt(this.getAttribute('data-index'))); }); @@ -204,7 +204,7 @@ user.Policy.MaxParentalRating = $('#selectMaxParentalRating', page).val() || null; - user.Policy.BlockUnratedItems = $('.chkUnratedItem', page).get().filter(function(i) { + user.Policy.BlockUnratedItems = $('.chkUnratedItem', page).get().filter(function (i) { return i.checked; @@ -237,16 +237,6 @@ saveUser(result, page); }); - // Disable default form submission - return false; - }, - - onScheduleFormSubmit: function () { - - var page = $(this).parents('.page'); - - saveSchedule(page); - // Disable default form submission return false; } @@ -262,65 +252,29 @@ minutes = parseInt(pct * 60); } - return new Date(2000, 1, 1, hours, minutes, 0, 0).toLocaleTimeString(); - } - - function populateHours(page) { - - var html = ''; - - for (var i = 0; i < 24; i++) { - - html += ''; - } - - html += ''; - - $('#selectStart', page).html(html); - $('#selectEnd', page).html(html); + return datetime.getDisplayTime(new Date(2000, 1, 1, hours, minutes, 0, 0)); } function showSchedulePopup(page, schedule, index) { schedule = schedule || {}; - $('#popupSchedule', page).popup('open'); + require(['components/accessschedule/accessschedule'], function (accessschedule) { + accessschedule.show({ + schedule: schedule + }).then(function (updatedSchedule) { - $('#fldScheduleIndex', page).val(index); + var schedules = getSchedulesFromPage(page); - $('#selectDay', page).val(schedule.DayOfWeek || 'Sunday'); - $('#selectStart', page).val(schedule.StartHour || 0); - $('#selectEnd', page).val(schedule.EndHour || 0); - } + if (index == -1) { + index = schedules.length; + } - function saveSchedule(page) { + schedules[index] = updatedSchedule; - var schedule = { - DayOfWeek: $('#selectDay', page).val(), - StartHour: $('#selectStart', page).val(), - EndHour: $('#selectEnd', page).val() - }; - - if (parseFloat(schedule.StartHour) >= parseFloat(schedule.EndHour)) { - - alert(Globalize.translate('ErrorMessageStartHourGreaterThanEnd')); - - return; - } - - var schedules = getSchedulesFromPage(page); - - var index = parseInt($('#fldScheduleIndex', page).val()); - - if (index == -1) { - index = schedules.length; - } - - schedules[index] = schedule; - - renderAccessSchedule(page, schedules); - - $('#popupSchedule', page).popup('close'); + renderAccessSchedule(page, schedules); + }); + }); } function getSchedulesFromPage(page) { @@ -379,9 +333,6 @@ showBlockedTagPopup(page); }); - populateHours(page); - - $('.scheduleForm').off('submit', UserParentalControlPage.onScheduleFormSubmit).on('submit', UserParentalControlPage.onScheduleFormSubmit); $('.userParentalControlForm').off('submit', UserParentalControlPage.onSubmit).on('submit', UserParentalControlPage.onSubmit); }).on('pageshow', "#userParentalControlPage", function () {