diff --git a/addons/website_quote/static/src/css/website_quotation.css b/addons/website_quote/static/src/css/website_quotation.css
index 6fa917b7621..c4bbd4d9c64 100644
--- a/addons/website_quote/static/src/css/website_quotation.css
+++ b/addons/website_quote/static/src/css/website_quotation.css
@@ -42,7 +42,6 @@
padding-left: 30px;
font-size: 90%;
}
-
@media (min-width: 992px) {
.o_website_quote .bs-sidebar .nav > .active > ul {
display: block;
diff --git a/addons/website_quote/static/src/js/website_quotation.js b/addons/website_quote/static/src/js/website_quotation.js
index 37f5e2a9a62..feb1901677a 100644
--- a/addons/website_quote/static/src/js/website_quotation.js
+++ b/addons/website_quote/static/src/js/website_quotation.js
@@ -1,101 +1,157 @@
(function () {
-'use strict';
-var website = openerp.website;
+ 'use strict';
-website.if_dom_contains('div.o_website_quote', function () {
+ var website = openerp.website;
+ website.quotation = {};
- $('a.js_update_line_json').on('click', function (ev) {
- ev.preventDefault();
- var $link = $(ev.currentTarget);
- var href = $link.attr("href");
- var order_id = href.match(/order_id=([0-9]+)/);
- var line_id = href.match(/update_line\/([0-9]+)/);
- var token = href.match(/token=(.*)/);
- openerp.jsonRpc("/quote/update_line", 'call', {
- 'line_id': line_id[1],
- 'order_id': parseInt(order_id[1]),
- 'token': token[1],
- 'remove': $link.is('[href*="remove"]'),
- 'unlink': $link.is('[href*="unlink"]')
- })
- .then(function (data) {
+ website.if_dom_contains('div.o_website_quote', function () {
+
+ // Add to SO button
+ website.quotation.UpdateLineButton = openerp.Widget.extend({
+ events: {
+ 'click' : 'onClick',
+ },
+ onClick: function(ev){
+ ev.preventDefault();
+ var self = this;
+ var href = this.$el.attr("href");
+ var order_id = href.match(/order_id=([0-9]+)/);
+ var line_id = href.match(/update_line\/([0-9]+)/);
+ var token = href.match(/token=(.*)/);
+ openerp.jsonRpc("/quote/update_line", 'call', {
+ 'line_id': line_id[1],
+ 'order_id': parseInt(order_id[1]),
+ 'token': token[1],
+ 'remove': self.$el.is('[href*="remove"]'),
+ 'unlink': self.$el.is('[href*="unlink"]')
+ }).then(function (data) {
if(!data){
location.reload();
}
- $link.parents('.input-group:first').find('.js_quantity').val(data[0]);
+ self.$el.parents('.input-group:first').find('.js_quantity').val(data[0]);
$('[data-id="total_amount"]>span').html(data[1]);
});
- return false;
- });
-
- var empty_sign = false;
- $('#modelaccept').on('shown.bs.modal', function (e) {
- $("#signature").empty().jSignature({'decor-color' : '#D1D0CE'});
- empty_sign = $("#signature").jSignature("getData",'image');
- });
-
- $('#sign_clean').on('click', function (e) {
- $("#signature").jSignature('reset');
- });
-
-
- $('form.js_accept_json').submit(function(ev){
- ev.preventDefault();
- var $link = $(ev.currentTarget);
- var href = $link.attr("action");
- var order_id = href.match(/accept\/([0-9]+)/);
- var token = href.match(/token=(.*)/);
- if (token)
- token = token[1];
-
- var signer_name = $("#name").val();
- var sign = $("#signature").jSignature("getData",'image');
- var is_empty = sign?empty_sign[1]==sign[1]:false;
- $('#signer').toggleClass('has-error', ! signer_name);
- $('#drawsign').toggleClass('panel-danger', is_empty).toggleClass('panel-default', ! is_empty);
-
- if (is_empty || ! signer_name)
- return false;
-
- openerp.jsonRpc("/quote/accept", 'call', {
- 'order_id': parseInt(order_id[1]),
- 'token': token,
- 'signer': signer_name,
- 'sign': sign?JSON.stringify(sign[1]):false,
- }).then(function (data) {
- $('#modelaccept').modal('hide');
- window.location.href = '/quote/'+order_id[1]+'/'+token+'?message=3';
+ return false;
+ },
});
- return false;
- });
- // automatically generate a menu from h1 and h2 tag in content
- var $container = $('body[data-target=".navspy"]');
- var ul = $('[data-id="quote_sidebar"]', $container);
- var sub_li = null;
- var sub_ul = null;
- $("[id^=quote_header_], [id^=quote_]", $container).attr("id", "");
- $("h1, h2", $container).each(function() {
- var id;
- switch (this.tagName.toLowerCase()) {
- case "h1":
- id = _.uniqueId('quote_header_');
- $(this.parentNode).attr('id',id);
- sub_li = $("
").html(''+$(this).text()+'').appendTo(ul);
- sub_ul = null;
- break;
- case "h2":
- id = _.uniqueId('quote_');
- if (sub_li) {
- if (!sub_ul) {
- sub_ul = $("").appendTo(sub_li);
- }
- $(this.parentNode).attr('id',id);
- $("- ").html(''+$(this).text()+'').appendTo(sub_ul);
+ var update_button_list = [];
+ $('a.js_update_line_json').each(function( index ) {
+ var button = new website.quotation.UpdateLineButton();
+ button.setElement($(this)).start();
+ update_button_list.push(button);
+ });
+
+ // Accept Modal, with jSignature
+ website.quotation.AcceptModal = openerp.Widget.extend({
+ events: {
+ 'shown.bs.modal': 'initSignature',
+ 'click #sign_clean': 'clearSignature',
+ 'submit #accept': 'submitForm',
+ },
+ initSignature: function(ev){
+ this.$("#signature").empty().jSignature({'decor-color' : '#D1D0CE'});
+ this.empty_sign = this.$("#signature").jSignature("getData",'image');
+ },
+ clearSignature: function(ev){
+ this.$("#signature").jSignature('reset');
+ },
+ submitForm: function(ev){
+ ev.preventDefault();
+ // extract data
+ var self = this;
+ var href = self.$el.find('form').attr("action");
+ var order_id = href.match(/accept\/([0-9]+)/);
+ var token = href.match(/token=(.*)/);
+ if (token){
+ token = token[1];
}
- break;
+ // process : display errors, or submit
+ var signer_name = self.$("#name").val();
+ var signature = self.$("#signature").jSignature("getData",'image');
+ var is_empty = signature ? this.empty_sign[1] == signature[1] : false;
+ self.$('#signer').toggleClass('has-error', !signer_name);
+ self.$('#drawsign').toggleClass('panel-danger', is_empty).toggleClass('panel-default', !is_empty);
+ if (is_empty || ! signer_name){
+ return false;
+ }
+ openerp.jsonRpc("/quote/accept", 'call', {
+ 'order_id': parseInt(order_id[1]),
+ 'token': token,
+ 'signer': signer_name,
+ 'sign': signature?JSON.stringify(signature[1]):false,
+ }).then(function (data) {
+ self.$el.modal('hide');
+ window.location.href = '/quote/'+order_id[1]+'/'+token+'?message=3';
+ });
+ return false;
+ },
+ });
+
+ var accept_modal = new website.quotation.AcceptModal();
+ accept_modal.setElement($('#modalaccept'));
+ accept_modal.start();
+
+ // Nav Menu ScrollSpy
+ website.quotation.NavigationSpyMenu = openerp.Widget.extend({
+ start: function(watched_selector){
+ this.authorized_text_tag = ['em', 'b', 'i', 'u'];
+ this.spy_watched = $(watched_selector);
+ this.generateMenu();
+ },
+ generateMenu: function(){
+ var self = this;
+ // reset ids
+ $("[id^=quote_header_], [id^=quote_]", this.spy_watched).attr("id", "");
+ // generate the new spy menu
+ var last_li = false;
+ var last_ul = null;
+ _.each(this.spy_watched.find("h1, h2"), function(el){
+ switch (el.tagName.toLowerCase()) {
+ case "h1":
+ var id = self.setElementId('quote_header_', el);
+ var text = self.extractText($(el));
+ last_li = $("
- ").html(''+text+'').appendTo(self.$el);
+ last_ul = false;
+ break;
+ case "h2":
+ var id = self.setElementId('quote_', el);
+ var text = self.extractText($(el));
+ if (last_li) {
+ if (!last_ul) {
+ last_ul = $("
").appendTo(last_li);
+ }
+ $("- ").html(''+text+'').appendTo(last_ul);
+ }
+ break;
+ }
+ });
+ },
+ setElementId: function(prefix, $el){
+ var id = _.uniqueId(prefix);
+ this.spy_watched.find($el).attr('id', id);
+ return id;
+ },
+ extractText: function($node){
+ var self = this;
+ var raw_text = [];
+ _.each($node.contents(), function(el){
+ var current = $(el);
+ if($.trim(current.text())){
+ var tagName = current.prop("tagName");
+ if(_.isUndefined(tagName) || (!_.isUndefined(tagName) && _.contains(self.authorized_text_tag, tagName.toLowerCase()))){
+ raw_text.push($.trim(current.text()));
+ }
+ }
+ });
+ return raw_text.join(' ');
}
+ });
+
+ var nav_menu = new website.quotation.NavigationSpyMenu();
+ nav_menu.setElement($('[data-id="quote_sidebar"]'));
+ nav_menu.start($('body[data-target=".navspy"]'));
+
});
-});
}());
diff --git a/addons/website_quote/views/website_quotation.xml b/addons/website_quote/views/website_quotation.xml
index 20ab233e933..c5a7aa34854 100644
--- a/addons/website_quote/views/website_quotation.xml
+++ b/addons/website_quote/views/website_quotation.xml
@@ -11,10 +11,8 @@
-
+
@@ -24,12 +22,13 @@
|
Unit Price |
Price |
+ |
|
-
+
|
@@ -94,11 +93,11 @@
|
-
+
@@ -120,22 +119,24 @@
-
-
+
+
+
+
@@ -156,27 +157,29 @@
+