diff --git a/website_contact_snippet/__init__.py b/website_contact_snippet/__init__.py new file mode 100644 index 0000000..7c68785 --- /dev/null +++ b/website_contact_snippet/__init__.py @@ -0,0 +1 @@ +# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/website_contact_snippet/__openerp__.py b/website_contact_snippet/__openerp__.py new file mode 100644 index 0000000..a1b1e0f --- /dev/null +++ b/website_contact_snippet/__openerp__.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Odoo, an open source suite of business apps +# This module copyright (C) 2015 bloopark systems (). +# +# 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 . +# +############################################################################## +{ + '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' + ], +} diff --git a/website_contact_snippet/readme.rst b/website_contact_snippet/readme.rst new file mode 100755 index 0000000..c0322bb --- /dev/null +++ b/website_contact_snippet/readme.rst @@ -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. \ No newline at end of file diff --git a/website_contact_snippet/static/src/img/thumbnail.png b/website_contact_snippet/static/src/img/thumbnail.png new file mode 100644 index 0000000..b2e3b01 Binary files /dev/null and b/website_contact_snippet/static/src/img/thumbnail.png differ diff --git a/website_contact_snippet/static/src/js/website_contact_snippet.editor.js b/website_contact_snippet/static/src/js/website_contact_snippet.editor.js new file mode 100644 index 0000000..130e77d --- /dev/null +++ b/website_contact_snippet/static/src/js/website_contact_snippet.editor.js @@ -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); + }); + }, + }); +}); \ No newline at end of file diff --git a/website_contact_snippet/static/src/xml/contact_form.xml b/website_contact_snippet/static/src/xml/contact_form.xml new file mode 100644 index 0000000..80ac79f --- /dev/null +++ b/website_contact_snippet/static/src/xml/contact_form.xml @@ -0,0 +1,50 @@ + + + + + + + + \ No newline at end of file diff --git a/website_contact_snippet/static/src/xml/contact_form_modal.xml b/website_contact_snippet/static/src/xml/contact_form_modal.xml new file mode 100644 index 0000000..87fbac6 --- /dev/null +++ b/website_contact_snippet/static/src/xml/contact_form_modal.xml @@ -0,0 +1,130 @@ + + + + + + + + +
+
+ +
+ +
+
+
+
+ + + + + + +
+
+ +
+ +
+
+
+
+ + +
+
+ +
+ +
+
+
+
+ + +
+
+ +
+ +
+
+
+
+ + +
diff --git a/website_contact_snippet/views/assets.xml b/website_contact_snippet/views/assets.xml new file mode 100644 index 0000000..44b8da3 --- /dev/null +++ b/website_contact_snippet/views/assets.xml @@ -0,0 +1,12 @@ + + + + + + + + diff --git a/website_contact_snippet/views/snippet.xml b/website_contact_snippet/views/snippet.xml new file mode 100644 index 0000000..768e3a7 --- /dev/null +++ b/website_contact_snippet/views/snippet.xml @@ -0,0 +1,20 @@ + + + + + + + + + + \ No newline at end of file