From 7e3edaf05c085ca6f058563768089f99e0f9b173 Mon Sep 17 00:00:00 2001 From: qiaomin Date: Thu, 9 Feb 2017 18:06:47 +0800 Subject: [PATCH] Modify "Interval" field to select format MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Modify the "Interval" filed in "Create Job" form to select format, support user to choose 'Continuous', 'Weeks', 'Days' and so on. This makes the user input life easier. Change-Id: Ida460d260d96c0b99f5ced035009221bba91b109 Closes-Bug: #1663235 --- .../jobs/templates/jobs/_info.html | 1 + disaster_recovery/jobs/workflows/create.py | 52 +++++++++++++------ .../freezer/js/freezer.jobs.create.infos.js | 40 ++++++++++++++ 3 files changed, 77 insertions(+), 16 deletions(-) create mode 100644 disaster_recovery/static/freezer/js/freezer.jobs.create.infos.js diff --git a/disaster_recovery/jobs/templates/jobs/_info.html b/disaster_recovery/jobs/templates/jobs/_info.html index f760a9e..673f165 100644 --- a/disaster_recovery/jobs/templates/jobs/_info.html +++ b/disaster_recovery/jobs/templates/jobs/_info.html @@ -9,5 +9,6 @@ + {% endblock %} diff --git a/disaster_recovery/jobs/workflows/create.py b/disaster_recovery/jobs/workflows/create.py index eb8d7d3..3463b21 100644 --- a/disaster_recovery/jobs/workflows/create.py +++ b/disaster_recovery/jobs/workflows/create.py @@ -106,18 +106,17 @@ class InfoConfigurationAction(workflows.Action): label=_("Start Date and Time"), required=False) - schedule_interval = forms.CharField( - label=_("Interval"), - required=False, - help_text=_("""Set the interval in the following format: - continuous, - N weeks, - N days, - N hours, - N minutes, - N seconds, - If no start date is provided the job - will start immediately""")) + interval_uint = forms.ChoiceField( + label=_("Interval Unit"), + help_text=_("Set the unit for the Interval"), + required=False) + + interval_value = forms.IntegerField( + label=_("Interval Value"), + initial=1, + min_value=1, + help_text=_("Set the interval value"), + required=False) schedule_end_date = forms.CharField( label=_("End Date and Time"), @@ -142,6 +141,17 @@ class InfoConfigurationAction(workflows.Action): except ValueError: return False + def populate_interval_uint_choices(self, request, context): + return [ + ('', _("Please choose a interval unit")), + ('continuous', _("Continuous")), + ('weeks', _("Weeks")), + ('days', _("Days")), + ('hours', _("Hours")), + ('minutes', _("Minutes")), + ('seconds', _("Seconds")), + ] + def _check_start_datetime(self, cleaned_data): if cleaned_data.get('schedule_start_date') and not \ self._validate_iso_format( @@ -151,13 +161,13 @@ class InfoConfigurationAction(workflows.Action): if (cleaned_data.get('schedule_start_date') and cleaned_data.get('schedule_end_date')) and\ - not cleaned_data.get('schedule_interval'): + not cleaned_data.get('schedule_unit'): msg = _("Please provide this value.") - self._errors['schedule_interval'] = self.error_class([msg]) + self._errors['schedule_unit'] = self.error_class([msg]) if (cleaned_data.get('schedule_end_date') and not cleaned_data.get('schedule_start_date')) and\ - not cleaned_data.get('schedule_interval'): + not cleaned_data.get('schedule_unit'): msg = _("Please provide this value.") self._errors['schedule_start_date'] = self.error_class([msg]) @@ -181,7 +191,8 @@ class InfoConfiguration(workflows.Step): 'job_id', 'actions', 'schedule_start_date', - 'schedule_interval', + 'interval_uint', + 'interval_value', 'schedule_end_date') @@ -198,6 +209,15 @@ class ConfigureJob(workflows.Workflow): def handle(self, request, context): try: + interval_unit = context['interval_uint'] + if not interval_unit or interval_unit == 'continuous': + context['schedule_interval'] = interval_unit + else: + interval_value = context['interval_value'] + schedule_interval = "{0} {1}".format(interval_value, + interval_unit) + + context['schedule_interval'] = schedule_interval if context['job_id'] != '': freezer_api.Job(request).update(context['job_id'], context) else: diff --git a/disaster_recovery/static/freezer/js/freezer.jobs.create.infos.js b/disaster_recovery/static/freezer/js/freezer.jobs.create.infos.js new file mode 100644 index 0000000..3d6aad8 --- /dev/null +++ b/disaster_recovery/static/freezer/js/freezer.jobs.create.infos.js @@ -0,0 +1,40 @@ +/* +# (c) Copyright 2014,2015 Hewlett-Packard Development Company, L.P. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +*/ + +/*global $*/ + +"use strict"; + +function showIntervalValue() { + $("#id_interval_value").closest(".form-group").show(); +} + +function hideIntervalValue() { + $("#id_interval_value").closest(".form-group").hide(); +} + +$("#id_interval_uint").change(function () { + var $interval_uint = $("#id_interval_uint").val(); + if ($interval_uint != 'continuous') { + showIntervalValue(); + } else { + hideIntervalValue(); + } +}); + +$(function () { + hideIntervalValue(); +});