WIP/ backoffice: keep track of submission channel (#7053)

This commit is contained in:
Frédéric Péters 2015-04-30 20:19:29 +02:00
parent 07da0cb34b
commit 07cc30ddaf
4 changed files with 115 additions and 0 deletions

View File

@ -1070,8 +1070,27 @@ class FormBackOfficeStatusPage(FormStatusPage):
def _q_index(self):
get_response().add_javascript(['jquery.js', 'qommon.admin.js'])
get_response().filter['sidebar'] = self.get_sidebar()
return self.status()
def get_sidebar(self):
if not self.filled.workflow_data or not self.filled.workflow_data.get('origin'):
return None
r = TemplateIO(html=True)
r += htmltext('<div id="origin-options" class="bo-block">')
origin_dict = self.filled.workflow_data.get('origin')
origin_source = origin_dict.get('source')
r += htmltext('<h3>%s - %s</h3>') % (_('Origin'),
_(submission.ORIGINS.get(origin_source)))
if origin_source == 'mail':
r += htmltext('<div style="text-align: center">')
r += htmltext('<a href="%s"><img src="%s.png" alt=""/></a>') % (
origin_dict.get('origin-mail-url'),
origin_dict.get('origin-mail-url'))
r += htmltext('</div>')
r += htmltext('</div>')
return r.getvalue()
class FakeField(object):
def __init__(self, id, type_, label):

View File

@ -42,6 +42,7 @@ class FormFillPage(PublicFormFillPage):
return html_top('submission', *args, **kwargs)
def get_sidebar(self, data):
get_response().add_javascript(['jquery.js', 'wcs.origin.js'])
r = TemplateIO(html=True)
if self.formdef.enable_tracking_codes:
@ -57,6 +58,31 @@ class FormFillPage(PublicFormFillPage):
else:
r += htmltext('<p>-</p>')
r += htmltext('<h3>%s</h3>') % _('Origin')
r += htmltext('<select id="origin">')
r += htmltext(' <option></option>')
for origin_key, origin_label in ORIGINS.items():
r += htmltext(' <option value="%s">%s</option>') % (
origin_key, _(origin_label))
r += htmltext('</select>')
r += htmltext('<div id="origin-options">')
r += htmltext('<div id="origin-options-phone" style="display: none">')
r += htmltext('<label>%s <input/></label>') % _('Phone Number')
r += htmltext('</div>')
r += htmltext('<div id="origin-options-mail" style="display: none">')
r += htmltext('<div style="text-align: center">')
r += htmltext('<input type="hidden"/>')
r += htmltext('<button>%s</button>') % _('Open Mails...')
r += htmltext('<img/>')
r += htmltext('</div>')
r += htmltext('</div>')
r += htmltext('</div>')
r += htmltext('<button id="origin-submit" style="display: none">%s</button>' % _('Save'))
return r.getvalue()
def form_side(self, step_no, page_no=0, log_detail=None, data=None, editing=None):
@ -71,6 +97,14 @@ class FormFillPage(PublicFormFillPage):
filled = self.formdef.data_class()()
filled.just_created()
filled.data = self.formdef.get_data(form)
if get_request().form.get('origin'):
origin_info = {}
origin_info['source'] = get_request().form.get('origin')
for field in ('origin-phone-number', 'origin-mail-url'):
if not field.startswith('origin-%s-' % origin_info['source']):
continue
origin_info[field] = get_request().form.get(field)
filled.update_workflow_data({'origin': origin_info})
filled.store()
self.keep_tracking_code(filled)
@ -87,6 +121,7 @@ class SubmissionDirectory(Directory):
_q_exports = ['']
def _q_index(self):
get_response().add_javascript(['jquery.js', 'wcs.origin.js'])
get_response().breadcrumb.append(('submission/', _('Submission')))
html_top('submission', _('Submission'))
formdefs = FormDef.select(order_by='name', ignore_errors=True)

View File

@ -912,3 +912,17 @@ fieldset.form-plus.closed legend:after {
a#filter-settings {
cursor: pointer;
}
#origin-options {
padding-top: 1em;
padding-bottom: 1em;
}
#origin-options img {
box-shadow: 0 0 3px black;
transform: rotate(2deg);
}
#origin-options a {
border: none;
}

View File

@ -0,0 +1,47 @@
$(function() {
$('#origin').on('change', function() {
$('#origin-options > div').hide();
if ($(this).val()) {
$('#origin-options > div#origin-options-' + $(this).val()).show();
$('#origin-submit').show();
}
});
$('#origin').val(window.localStorage['origin']);
$('#origin-options-phone input').val(window.localStorage['origin-phone-number']);
$('#origin-options-mail input').val(window.localStorage['origin-mail-url']);
if (window.localStorage['origin-mail-url']) {
$('#origin-options-mail img').attr('src', window.localStorage['origin-mail-url'] + '.png');
$('#origin-options-mail button').hide();
}
$('#origin').trigger('change');
$('#origin-submit').on('click', function() {
/* temporarily attach selection to local storage */
window.localStorage['origin'] = $('#origin').val();
window.localStorage['origin-phone-number'] = $('#origin-options-phone input').val();
window.localStorage['origin-mail-url'] = $('#origin-options-mail input').val();
});
var maarch_window = null;
$('#origin-options-mail button').on('click', function() {
maarch_window = window.open('http://localhost/pdfjs/web/viewer.html');
});
$(window).on("message", function(e) {
var url = e.originalEvent.data;
if ($('#origin-options-mail').length == 0) {
window.localStorage['origin'] = 'mail';
window.localStorage['origin-mail-url'] = url;
} else {
$('#origin-options-mail input').val(url);
$('#origin-options-mail img').attr('src', url + '.png');
$('#origin-options-mail button').hide();
}
});
$('div.form-validation form').on('submit', function(e) {
/* add origin details to main form */
var fields = ['origin', 'origin-phone-number', 'origin-mail-url'];
for (var i=0; i<fields.length; i++) {
$(this).append($('<input type="hidden">').attr('name', fields[i]).val(window.localStorage[fields[i]]));
}
window.localStorage.clear(); /* XXX: would need to be more targetted if localStorage was used elsewhere */
return true;
});
});