[ADD] hibou_professional: initial commit for 13.0

This commit is contained in:
Jared Kipe
2020-09-30 11:08:30 -07:00
parent 58a2cf52a0
commit 0dd585d106
9 changed files with 682 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
.hibou_professional_systray .o_mail_systray_dropdown {
max-height: 580px !important;
}
.hibou_professional_systray .o_mail_systray_dropdown_items {
max-height: 578px !important;
}
.hibou_professional_systray .subscription_form button {
margin-top: 6px;
}
.hibou_professional_systray .hibou-icon-small {
margin-top: -2px;
}
.hibou_professional_systray .hibou_professional_help {
color: #0a6fa2;
}
.hibou_professional_systray .o_preview_title span {
font-weight: bold;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.4 KiB

View File

@@ -0,0 +1,275 @@
odoo.define('hibou_professional.core', function (require) {
"use strict";
var Widget = require('web.Widget');
var SystrayMenu = require('web.SystrayMenu');
var HibouProfessionalSystrayWidget = Widget.extend({
template: 'HibouProfessionalSystrayWidget',
start: function() {
var self = this;
self.expiration_date = false;
self.expiration_reason = false;
self.professional_code = false;
this.types = [['lead', 'Sales'], ['ticket', 'Support']];
this.message_subjects = {'lead': [], 'ticket': [], 'task': []};
self.expiring = false;
self.expired = false;
self.dbuuid = false;
self.quote_url = false;
self.is_admin = false;
self.allow_admin_message = false;
self.allow_message = false;
this._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_status',
}).then(function (result) {
self.handleStatusUpdate(result);
});
return this._super();
},
get_subjects: function(type) {
if (this.message_subjects && this.message_subjects[type]) {
return this.message_subjects[type]
}
return [];
},
set_error: function(error) {
this.$('.hibou_professional_error').text(error);
},
update_message_type: function(el) {
var selected_type = this.$('select.hibou_message_type').val();
if (selected_type && this.$('.hibou_subject_selection_option.' + selected_type).length > 0) {
this.$('#hibou_subject_selection').show();
this.$('.hibou_subject_selection_option').hide().attr('disabled', true);
this.$('.hibou_subject_selection_option.' + selected_type).show().attr('disabled', false);
var selected_subject = this.$('.hibou_subject_selection_option.' + selected_type)[0];
this.$('select.hibou_subject_selection').val(selected_subject.value);
} else if (selected_type) {
this.$('select.hibou_subject_selection').val('0');
this.$('#hibou_subject_selection').hide();
} else {
this.$('#hibou_subject_selection').hide();
this.$('#hibou_message_priority').hide();
this.$('#hibou_message_subject').hide();
}
this.update_subject_selection();
},
update_subject_selection: function(el) {
var selected_subject = this.$('select.hibou_subject_selection').val();
if (selected_subject == '0') {
this.$('#hibou_message_priority').show();
this.$('#hibou_message_subject').show();
} else {
this.$('#hibou_message_priority').hide();
this.$('#hibou_message_subject').hide();
}
},
update_message_subjects: function(subjects_by_type) {
// TODO actually update instead of overriding...
this.message_subjects = subjects_by_type;
this.renderElement();
},
button_update_subscription: function() {
var self = this;
var professional_code = self.$('input.hibou_professional_code').val();
if (!professional_code) {
alert('Please enter a subscription code first.');
return;
}
self.$('.update_subscription').prop('disabled', 'disabled');
self._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_update',
args: [professional_code],
}).then(function (result) {
self.$('.update_subscription').prop('disabled', false);
self.handleStatusUpdate(result);
});
},
button_update_message_preferences: function() {
var self = this;
var allow_admin_message = self.$('input.hibou_allow_admin_message').prop('checked');
var allow_message = self.$('input.hibou_allow_message').prop('checked');
self.$('.update_message_preferences').prop('disabled', 'disabled');
self._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_update_message_preferences',
args: [allow_admin_message, allow_message],
}).then(function (result) {
self.$('.update_message_preferences').prop('disabled', false);
self.handleStatusUpdate(result);
});
},
button_quote: function() {
var self = this;
var message_p = self.$('.button-quote-link p');
message_p.text('Retrieving URL...');
self._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_quote',
}).then(function (result) {
if (result && result['url']) {
self.quote_url = result.url
self.$('.button-quote-link').attr('href', self.quote_url);
message_p.text('Quote URL ready. Click again!');
} else {
message_p.text('Error with quote url. Maybe the database token is incorrect.');
}
});
},
button_send_message: function() {
var self = this;
var message_type = self.$('select.hibou_message_type').val();
var message_priority = self.$('select.hibou_message_priority').val();
var message_subject = self.$('input.hibou_message_subject').val();
var message_subject_id = self.$('select.hibou_subject_selection').val();
var current_url = window.location.href;
if (message_subject_id == '0' && (!message_subject || message_subject.length < 3)) {
alert('Please enter a longer subject.');
return;
}
var message_body = self.$('textarea.hibou_message_body').val();
self.$('.hibou_send_message').prop('disabled', 'disabled');
self._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_send_message',
args: [message_type, message_priority, message_subject, message_body, current_url, message_subject_id],
}).then(function (result) {
// TODO result will have a subject to add to the subjects and re-render.
self.$('.hibou_send_message').prop('disabled', false);
var message_response = self.$('.hibou_message_response');
var access_link = self.$('.hibou_message_response a');
var message_form = self.$('.hibou_message_form');
if (!result) {
access_link.text('An error has occured.')
} else {
if (result.error) {
access_link.text(result.error);
} else {
access_link.text(result.message || 'Your message has been received.')
}
if (result.access_url) {
access_link.attr('href', result.access_url);
}
}
message_response.show();
message_form.hide();
});
},
button_get_messages: function() {
var self = this;
var $button = this.$('.hibou_get_messages');
$button.prop('disabled', 'disabled');
self._rpc({
model: 'publisher_warranty.contract',
method: 'hibou_professional_get_messages',
args: [],
}).then(function (result) {
$button.prop('disabled', false);
if (result['message_subjects']) {
self.update_message_subjects(result.message_subjects);
setTimeout(function () {
self.$('.dropdown-toggle').click();
}, 100);
} else if (result['error']) {
self.set_error(result['error']);
}
});
},
renderElement: function() {
var self = this;
this._super();
this.update_message_type();
this.update_subject_selection();
this.$('select.hibou_message_type').on('change', function(el) {
self.update_message_type(el);
});
this.$('select.hibou_subject_selection').on('change', function(el) {
self.update_subject_selection(el);
});
// Update Subscription Button
this.$('.update_subscription').on('click', function(e){
e.preventDefault();
e.stopPropagation();
self.button_update_subscription();
});
this.$('.hibou_get_messages').on('click', function(e){
e.preventDefault();
e.stopPropagation();
self.button_get_messages();
});
// Retrieve quote URL
this.$('.button-quote-link').on('click', function(e){
if (self.quote_url) {
return; // allow default url click event
}
e.preventDefault();
e.stopPropagation();
self.button_quote();
});
// Update Message Preferences Button
this.$('.update_message_preferences').on('click', function(e){
e.preventDefault();
e.stopPropagation();
self.button_update_message_preferences();
});
// Send Message Button
this.$('.hibou_send_message').on('click', function(e){
e.preventDefault();
e.stopPropagation();
self.button_send_message();
});
// Kill the default click event
this.$('.hibou_message_form_container').on('click', function (e) {
//e.preventDefault();
e.stopPropagation();
})
},
handleStatusUpdate: function(status) {
this.expiration_date = status.expiration_date;
this.expiration_reason = status.expiration_reason;
this.professional_code = status.professional_code;
this.types = [['lead', 'Sales'], ['ticket', 'Support']];
if (this.professional_code) {
this.types.push(['task', 'Project Manager/Developer'])
}
this.expiring = status.expiring;
this.expired = status.expired;
this.dbuuid = status.dbuuid;
this.is_admin = status.is_admin;
this.allow_admin_message = status.allow_admin_message;
this.allow_message = status.allow_message;
this.renderElement();
},
});
SystrayMenu.Items.push(HibouProfessionalSystrayWidget);
return {
HibouProfessionalSystrayWidget: HibouProfessionalSystrayWidget,
};
});

View File

@@ -0,0 +1,137 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="HibouProfessionalSystrayWidget">
<li class="hibou_professional_systray o_mail_systray_item">
<a class="dropdown-toggle o-no-caret" data-toggle="dropdown" aria-expanded="false" data-flip="false" data-display="static" href="#">
<img t-if="! (widget.expiring || widget.expired)" class="hibou-icon-small" width="16px" height="16px" src="hibou_professional/static/src/img/hibou_icon_small.png" alt="Hibou Icon"/>
<i class="fa fa-exclamation-triangle" t-if="widget.expiring || widget.expired"/>
<span class="expiration_message" t-if="widget.expiring" t-esc="widget.expiring"/>
<span class="expiration_message" t-if="widget.expired" t-esc="widget.expired"/>
</a>
<div class="dropdown-menu dropdown-menu-right o_mail_systray_dropdown" role="menu">
<div class="o_mail_systray_dropdown_items">
<a href="https://odoo-hibou-test12.hibou-test-odoo.us-w-p1.hibou.me/help?utm_source=db&amp;utm_medium=help" target="_blank">
<!-- <a href="https://hibou.io/help?utm_source=db&amp;utm_medium=help" target="_blank">-->
<div class="o_mail_preview">
<div class="o_preview_info">
<div class="o_preview_title">
<span class="o_preview_name hibou_professional_help">
Hibou Professional Help
</span>
</div>
<div>
<p>We're here to help!<br/>Click here to review Hibou's help resources or to contact us today.</p>
</div>
<div class="text-danger hibou_professional_error"/>
</div>
</div>
</a>
<div t-if="widget.allow_message || (widget.allow_admin_message &amp;&amp; widget.is_admin)" class="o_mail_preview hibou_message_form_container">
<div class="o_preview_info">
<div class="o_preview_title">
<span class="o_preview_name hibou_professional_help">Talk to Hibou!</span>
</div>
<div>
<br/>
<p class="get_messages">
<button class="hibou_get_messages btn btn-secondary btn-sm">Retrieve Recent Subjects</button>
</p>
</div>
<div class="hibou_message_form">
<t t-set="subject_types" t-value="widget.types"/>
<p>
<label for="hibou_message_type">Who do you want to talk to?</label>
<select class="hibou_message_type form-control" name="hibou_message_type">
<t t-foreach="subject_types" t-as="type">
<option t-attf-value="#{type[0]}" t-esc="type[1]"/>
</t>
</select>
</p>
<p id="hibou_subject_selection">
<label for="hibou_subject_selection">Update Existing</label>
<select class="hibou_subject_selection form-control" name="hibou_subject_selection">
<t t-foreach="subject_types" t-as="type">
<t t-foreach="widget.get_subjects(type[0])" t-as="subject">
<option t-attf-value="#{subject[0]}" t-attf-class="hibou_subject_selection_option #{type[0]}" t-esc="subject[1]"/>
</t>
</t>
<option value="0">New</option>
</select>
</p>
<p id="hibou_message_priority">
<label for="hibou_message_priority">Priority</label>
<select class="hibou_message_priority form-control" name="hibou_message_priority">
<option value="0">Low priority</option>
<option value="1">Medium priority</option>
<option value="2">High priority</option>
<option value="3">Urgent</option>
</select>
</p>
<p id="hibou_message_subject">
<label for="hibou_message_subject">Subject</label>
<input type="text" class="hibou_message_subject form-control" name="hibou_message_subject"/>
</p>
<p>
<p>You can use <a href="https://www.markdownguide.org/cheat-sheet/" target="_blank">Markdown</a> for formatting.</p>
<textarea rows="5" class="hibou_message_body form-control" name="hibou_message_body"/>
</p>
<button type="submit" class="hibou_send_message btn btn-primary">Send</button>
</div>
<div class="hibou_message_response" style="display: none;">
<a target="_blank">Click to view your message</a>
</div>
</div>
</div>
<t t-if="widget.expiration_reason == 'trial' || (! widget.expiration_reason) || widget.expired || widget.expiring">
<a class="button-quote-link" target="_blank">
<div class="o_mail_preview">
<div class="o_preview_info">
<div class="o_preview_title">
<span class="o_preview_name hibou_professional_help">
See pricing and get a Quote
</span>
</div>
<div>
<p>Click here to review Hibou's pricing and start a new Professional Subscription.</p>
</div>
</div>
</div>
</a>
<div class="o_mail_preview subscription_form">
<div class="o_preview_info">
<div class="o_preview_title">
<p>
<span t-if="widget.expiration_reason == 'trial'">You are on a trial of Hibou Professional.<br/></span>
If you have a subscription code, please enter it here.
</p>
</div>
<div>
<input type="text" name="hibou_professional_code form-control" class="hibou_professional_code"/>
<button type="submit" class="update_subscription btn btn-primary">Update Subscription</button>
</div>
</div>
</div>
</t>
<div t-if="widget.is_admin" class="o_mail_preview message_preferences_form">
<div class="o_preview_info">
<div class="o_preview_title">
<p>
You can send messages (tickets, project tasks, etc.) directly to Hibou using this dropdown.<br/><br/>Select which users can send messages.
</p>
</div>
<div>
<p>
<input type="checkbox" t-att-checked="widget.allow_admin_message=='1' or None" name="hibou_allow_admin_message" class="hibou_allow_admin_message"/> Admin Users (like yourself)
</p>
<p>
<input type="checkbox" t-att-checked="widget.allow_message=='1' or None" name="hibou_allow_message" class="hibou_allow_message"/> All Internal Users
</p>
<button type="submit" class="update_message_preferences btn btn-secondary">Update Message Preferences</button>
</div>
</div>
</div>
</div>
</div>
</li>
</t>
</templates>