Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions website_contact_snippet/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# -*- coding: utf-8 -*-
42 changes: 42 additions & 0 deletions website_contact_snippet/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Odoo, an open source suite of business apps
# This module copyright (C) 2015 bloopark systems (<http://bloopark.de>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Contact Snippet',
'description': 'Snippet for simple contact form with lead creation',
'category': 'Themes/Corporate',

'author': "bloopark systems GmbH & Co. KG",
'website': "http://www.bloopark.de",

'version': '1.0',

'data': [
'views/assets.xml',
'views/snippet.xml',
'static/src/xml/contact_form.xml'
],

'depends': [
'website',
'website_crm',
'website_form'
],
}
8 changes: 8 additions & 0 deletions website_contact_snippet/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
====================
Contact Form Snippet
====================

Dynamic snippet to allow web forms on Odoo pages outside of the contact page. Easily create leads by positioning the snippet
at strategic positions on your website. Leads are collected just as you are used to in the backend.
Currently the snippet allows to add/remove preset fields that exist in the original contact form. For future development, we are
aiming to provide the possibility to add custom fields.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
odoo.define('website_contact_snippet.editor', function(require) {
'use strict';

var options = require('web_editor.snippets.options');
var ajax = require('web.ajax');
var snippet_editor = require('web_editor.snippet.editor');
var core = require('web.core');
var qweb = core.qweb;

ajax.loadXML('/website_contact_snippet/static/src/xml/contact_form_modal.xml', qweb);

options.registry.website_contact_snippet = options.Class.extend({
form_opt: function(type, value, $li) {
if (type !== 'click') {return};
var self = this;
self.$modal = $(qweb.render("website_contact_snippet.contactus_form_modal"));
self.$modal.appendTo('body');
self.$modal.modal();

var $subData = self.$modal.find($('#sub-data')),
$sendForm = self.$target.find($('.o_website_form_send').closest('.form-group')),
formItems = ['name','email','phone','company','subject','message'],
modalIds = formItems.map(function(formItem) {
return formItem = self.$modal.find($('#' + formItem));
});

_.each(formItems, function(formItem) {
form_to_modal(formItem);
});

self.addEventHandler(modalIds, 'click', function() {
($(this).attr('checked')) ? $(this).attr('checked', false) : $(this).attr('checked', true);
});

$subData.on('click', function() {
formItems.forEach(function(formItem) {
modal_to_form(formItem);
});
});

function modal_to_form(formItem) {
var $formEl = self.$target.find($('.form-' + formItem)),
$modalCheck = self.$modal.find($('#' + formItem));

if ($modalCheck.attr('checked') === 'checked' && $formEl.length < 1) {

var template = $(qweb.render("website_contact_snippet.form_" + formItem));
template.insertBefore($sendForm);

} else if ($modalCheck.attr('checked') === 'checked' && $formEl.length > 0) {

(formItem === 'subject') ? $formEl.removeClass('hidden').val('') : '';

} else if ($modalCheck.attr('checked') !== 'checked') {

(formItem !== 'subject') ? $formEl.remove() : $formEl.addClass('hidden').val('Message from contact snippet');
}
}

function form_to_modal(formItem) {
var $formEl = self.$target.find($('.form-' + formItem)),
$modalCheck = self.$modal.find($('#' + formItem));

($formEl.length > 0 && formItem !== 'subject' || formItem === 'subject' && !$formEl.hasClass('hidden'))
? $modalCheck.attr('checked', true)
: $modalCheck.attr('checked', false);
}

this.$modal.on('hidden.bs.modal', function () {
$(this).remove();
});
},

addEventHandler: function (array, type, func) {
var len = array.length;
$(array).each(function(index, item) {
$(item).bind(type, func);
});
},
});
});
50 changes: 50 additions & 0 deletions website_contact_snippet/static/src/xml/contact_form.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data>

<template id="contactus_form" name="Contact Form">
<section class="website-form-snippet">
<div>
<form action="/website_form/" method="post" data-model_name="crm.lead" class="s_website_form form-horizontal container mt32" enctype="multipart/form-data">
<div class="row">
<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>
<div class="form-group form-name form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="contact_name">Your Name</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="contact_name" required=""/>
</div>
</div>
</div>
<div class="form-group form-email form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="email_from">Email</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="email_from" required=""/>
</div>
</div>
</div>
<div class="form-group form-subject form-field o_website_form_required col-md-12 hidden">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="name">Subject</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="name" required="" value="Message from contact snippet"/>
</div>
</div>
</div>
<div class="form-group col-md-12">
<div class="row">
<div class="col-md-offset-3 col-sm-offset-4 col-sm-8 col-md-7">
<button class="btn btn-primary btn-lg o_website_form_send">Send</button>
<span id="o_website_form_result"></span>
</div>
</div>
</div>
</div>
</form>
</div>
</section>
</template>

</data>
</openerp>
130 changes: 130 additions & 0 deletions website_contact_snippet/static/src/xml/contact_form_modal.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">

<t t-name="website_contact_snippet.contactus_form_modal">
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">


<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal"></button>
<h4 class="modal-title">Modal Header</h4>
</div>
<div class="modal-body row">
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Name</label>
<label class="col-sm-5">
<input id="name" type="checkbox"/>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Email</label>
<label class="col-sm-5">
<input id="email" type="checkbox"/>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Phone</label>
<label class="col-sm-5">
<input id="phone" type="checkbox"/>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Company</label>
<label class="col-sm-5">
<input id="company" type="checkbox"/>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Subject</label>
<label class="col-sm-5">
<input id="subject" type="checkbox"/>
</label>
</div>
</div>
<div class="col-sm-6">
<div class="checkbox">
<label class="col-sm-7 pre_label">Message</label>
<label class="col-sm-5">
<input id="message" type="checkbox"/>
</label>
</div>
</div>
</div>
<div class="modal-footer">
<button id="cancel" type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
<button id="sub-data" type="button" class="btn btn-primary" data-dismiss="modal">Apply</button>
</div>
</div>

</div>
</div>
</t>

<t t-name="website_contact_snippet.form_name">
<div class="form-group form-name form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="contact_name">Your Name</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="contact_name" required=""/>
</div>
</div>
</div>
</t>

<t t-name="website_contact_snippet.form_email">
<div class="form-group form-email form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="email_from">Email</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="email_from" required=""/>
</div>
</div>
</div>
</t>

<t t-name="website_contact_snippet.form_phone">
<div class="form-group form-field form-phone col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="phone">Phone Number</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" placeholder="e.g. (+32).81.81.37.00" name="phone"/>
</div>
</div>
</div>
</t>

<t t-name="website_contact_snippet.form_company">
<div class="form-group form-company form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="partner_name">Your Company</label>
<div class="col-md-7 col-sm-8">
<input type="text" class="form-control o_website_form_input" name="partner_name" required=""/>
</div>
</div>
</div>
</t>

<t t-name="website_contact_snippet.form_message">
<div class="form-group form-message form-field o_website_form_required_custom col-md-12">
<div class="row">
<label class="col-md-3 col-sm-4 control-label" for="description">Your Question</label>
<div class="col-md-7 col-sm-8">
<textarea class="form-control o_website_form_input" name="description" required=""></textarea>
</div>
</div>
</div>
</t>


</templates>
12 changes: 12 additions & 0 deletions website_contact_snippet/views/assets.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data>

<template id="s_contact_form_editor_js" inherit_id="website.assets_editor" priority="900" active="True">
<xpath expr="." position="inside">
<script src="/website_contact_snippet/static/src/js/website_contact_snippet.editor.js"></script>
</xpath>
</template>

</data>
</openerp>
20 changes: 20 additions & 0 deletions website_contact_snippet/views/snippet.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8" ?>
<openerp>
<data>

<template id="website-contact-snippets" inherit_id="website.snippets" name="Contact Snippet">
<xpath expr="//div[@id='snippet_structure']//div[@class='o_panel_body']" position="inside">
<t t-snippet="website_contact_snippet.contactus_form" t-thumbnail="/website_contact_snippet/static/src/img/thumbnail.png"/>
</xpath>
</template>

<template id="website-contact-snippet-options" inherit_id="website.snippet_options">
<xpath expr="//div[@data-js='blog-style']" position="before">
<div data-js="website_contact_snippet" data-selector="section.website-form-snippet">
<li data-form_opt=""><a><i class="fa fa-fw fa-cog"></i>Form Fields</a></li>
</div>
</xpath>
</template>

</data>
</openerp>