Exemplo n.º 1
0
 def setup_crispy(self):
     self.helper = HQFormHelper()
     self.helper.form_method = 'POST'
     self.helper.layout = crispy.Layout(
         crispy.Fieldset(
             _("Default Gateways"),
             hqcrispy.B3MultiField(
                 _("Default Gateway by Prefix"),
                 hqcrispy.ErrorsOnlyField('backend_map'),
                 crispy.Div(
                     data_bind="template: {"
                               " name: 'ko-template-backend-map', "
                               " data: $data"
                               "}"
                 ),
             ),
             'catchall_backend_id',
         ),
         hqcrispy.FormActions(
             StrictButton(
                 _("Save"),
                 type="submit",
                 css_class='btn-primary'
             ),
         ),
     )
Exemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        if 'domain' in kwargs:
            self.domain = kwargs.pop('domain')

        self.process_structured_sms = False
        if 'process_structured' in kwargs:
            self.process_structured_sms = kwargs.pop('process_structured')

        super(KeywordForm, self).__init__(*args, **kwargs)

        self.fields['sender_content_type'].choices = self.content_type_choices
        self.fields[
            'other_recipient_content_type'].choices = self.content_type_choices

        self.fields['other_recipient_id'].choices = self.group_choices
        self.fields[
            'sender_app_and_form_unique_id'].choices = self.form_choices
        self.fields[
            'other_recipient_app_and_form_unique_id'].choices = self.form_choices
        self.fields[
            'structured_sms_app_and_form_unique_id'].choices = self.form_choices

        from corehq.apps.reminders.views import KeywordsListView
        self.helper = FormHelper()
        self.helper.form_class = "form form-horizontal"
        self.helper.label_class = 'col-sm-3 col-md-2'
        self.helper.field_class = 'col-sm-9 col-md-8 col-lg-6'

        layout_fields = [
            crispy.Fieldset(
                _('Basic Information'),
                crispy.Field(
                    'keyword',
                    data_bind="value: keyword, "
                    "valueUpdate: 'afterkeydown', "
                    "event: {keyup: updateExampleStructuredSMS}",
                ),
                crispy.Field(
                    'description',
                    data_bind="text: description",
                ),
            ),
        ]
        if self.process_structured_sms:
            layout_fields.append(
                crispy.Fieldset(
                    _("Structured Message Options"),
                    crispy.Field(
                        'structured_sms_app_and_form_unique_id',
                        data_bind="value: structuredSmsAppAndFormUniqueId",
                        css_class="hqwebapp-select2",
                    ),
                    hqcrispy.B3MultiField(
                        _("Delimiters"),
                        crispy.Div(
                            crispy.Div(InlineField(
                                twbscrispy.PrependedText(
                                    'use_custom_delimiter',
                                    '',
                                    data_bind="checked: useCustomDelimiter, "
                                    "click: updateExampleStructuredSMS"),
                                block_css_class="span2",
                            ),
                                       css_class='col-md-4 col-lg-4'),
                            crispy.Div(InlineField(
                                'delimiter',
                                data_bind="value: delimiter, "
                                "valueUpdate: 'afterkeydown', "
                                "event: {keyup: updateExampleStructuredSMS},"
                                "visible: useCustomDelimiter",
                                block_css_class="span4",
                            ),
                                       css_class='col-md-4 col-lg-4')),
                    ),
                    hqcrispy.B3MultiField(
                        _("Named Answers"),
                        crispy.Div(InlineField(
                            twbscrispy.PrependedText(
                                'use_named_args',
                                '',
                                data_bind="checked: useNamedArgs, "
                                "click: updateExampleStructuredSMS"), ),
                                   css_class='col-md-4 col-lg-4'),
                        hqcrispy.ErrorsOnlyField('named_args'),
                        crispy.Div(data_bind="template: {"
                                   " name: 'ko-template-named-args', "
                                   " data: $data"
                                   "}, "
                                   "visible: useNamedArgs", ),
                    ),
                    hqcrispy.B3MultiField(
                        _("Joining Characters"),
                        crispy.Div(
                            crispy.Div(InlineField(
                                twbscrispy.PrependedText(
                                    'use_named_args_separator',
                                    '',
                                    data_bind="checked: useNamedArgsSeparator, "
                                    "click: updateExampleStructuredSMS"), ),
                                       css_class='col-md-4 col-lg-4'),
                            crispy.Div(InlineField(
                                'named_args_separator',
                                data_bind="value: namedArgsSeparator, "
                                "valueUpdate: 'afterkeydown', "
                                "event: {keyup: updateExampleStructuredSMS},"
                                "visible: useJoiningCharacter",
                            ),
                                       css_class='col-md-6 col-lg-4')),
                        data_bind="visible: useNamedArgs",
                    ),
                    hqcrispy.B3MultiField(
                        _("Example Structured Message"),
                        crispy.HTML('<pre style="background: white;" '
                                    'data-bind="text: exampleStructuredSms">'
                                    '</pre>'),
                    ),
                ), )
        layout_fields.extend([
            crispy.Fieldset(
                _("Response"),
                crispy.Field(
                    'sender_content_type',
                    data_bind="value: senderContentType",
                ),
                crispy.Div(
                    crispy.Field(
                        'sender_message',
                        data_bind="text: senderMessage",
                    ),
                    data_bind="visible: isMessageSMS",
                ),
                crispy.Div(
                    crispy.Field(
                        'sender_app_and_form_unique_id',
                        data_bind="value: senderAppAndFormUniqueId",
                        css_class="hqwebapp-select2",
                    ),
                    data_bind="visible: isMessageSurvey",
                ),
                crispy.Field(
                    'other_recipient_content_type',
                    data_bind="value: otherRecipientContentType",
                ),
                hqcrispy.B3MultiField(
                    "",
                    crispy.Div(
                        crispy.HTML(
                            '<h4 style="margin-bottom: 20px;">%s</h4>' %
                            _("Recipient Information"), ),
                        crispy.Field(
                            'other_recipient_type',
                            data_bind="value: otherRecipientType",
                        ),
                        crispy.Div(
                            crispy.Field(
                                'other_recipient_id',
                                data_bind="value: otherRecipientId",
                            ),
                            data_bind="visible: showRecipientGroup",
                        ),
                        crispy.Div(
                            crispy.Field(
                                'other_recipient_message',
                                data_bind="value: otherRecipientMessage",
                            ),
                            data_bind=
                            "visible: otherRecipientContentType() == 'sms'",
                        ),
                        crispy.Div(
                            crispy.Field(
                                'other_recipient_app_and_form_unique_id',
                                data_bind=
                                "value: otherRecipientAppAndFormUniqueId",
                                css_class="hqwebapp-select2",
                            ),
                            data_bind=
                            "visible: otherRecipientContentType() == 'survey'",
                        ),
                        css_class="well",
                        data_bind="visible: notifyOthers",
                    ),
                ),
            ),
            crispy.Fieldset(
                _("Advanced Options"),
                twbscrispy.PrependedText(
                    'override_open_sessions',
                    '',
                    data_bind="checked: overrideOpenSessions",
                ),
                'allow_keyword_use_by',
            ),
            hqcrispy.FormActions(
                twbscrispy.StrictButton(
                    _("Save"),
                    css_class='btn-primary',
                    type='submit',
                ),
                crispy.HTML(
                    '<a href="%s" class="btn btn-default">Cancel</a>' %
                    reverse(KeywordsListView.urlname, args=[self.domain]))),
        ])
        self.helper.layout = crispy.Layout(*layout_fields)