[IMP] mass_mailing: added kanban views for mass_mailing, implemented segment for campaigns. Moved sparkline and gauge widgets to web.
Segment: template, date, mails. Campaign: grouped statistics. bzr revid: tde@openerp.com-20130903145936-nwy250w1suxmtbl3
This commit is contained in:
parent
07a32dae60
commit
903ca548c7
|
@ -121,7 +121,6 @@ Dashboard for CRM will include:
|
|||
'static/src/css/crm.css'
|
||||
],
|
||||
'js': [
|
||||
'static/lib/sparkline/jquery.sparkline.js',
|
||||
'static/src/js/crm_case_section.js',
|
||||
],
|
||||
'installable': True,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -8,27 +8,4 @@ openerp.crm = function(openerp) {
|
|||
}
|
||||
},
|
||||
});
|
||||
|
||||
openerp.crm.SparklineBarWidget = openerp.web_kanban.AbstractField.extend({
|
||||
className: "oe_sparkline_bar",
|
||||
start: function() {
|
||||
var self = this;
|
||||
var title = this.$node.html();
|
||||
setTimeout(function () {
|
||||
var value = _.pluck(self.field.value, 'value');
|
||||
var tooltips = _.pluck(self.field.value, 'tooltip');
|
||||
self.$el.sparkline(value, {
|
||||
type: 'bar',
|
||||
barWidth: 5,
|
||||
tooltipFormat: '{{offset:offset}} {{value}}',
|
||||
tooltipValueLookups: {
|
||||
'offset': tooltips
|
||||
},
|
||||
});
|
||||
self.$el.tipsy({'delayIn': 0, 'html': true, 'title': function(){return title}, 'gravity': 'n'});
|
||||
}, 0);
|
||||
},
|
||||
});
|
||||
openerp.web_kanban.fields_registry.add("sparkline_bar", "openerp.crm.SparklineBarWidget");
|
||||
|
||||
};
|
||||
|
|
|
@ -63,12 +63,16 @@ class mail_mail(osv.Model):
|
|||
'notification': fields.boolean('Is Notification',
|
||||
help='Mail has been created to notify people of an existing mail.message'),
|
||||
# Bounce and tracking
|
||||
'opened': fields.integer(
|
||||
'opened': fields.datetime(
|
||||
'Opened',
|
||||
help='Number of times this email has been seen, using the OpenERP tracking.'),
|
||||
'replied': fields.integer(
|
||||
'Reply Received',
|
||||
help='If checked, a reply to this email has been received.'),
|
||||
help='Date when this email has been opened for the first time.'),
|
||||
'replied': fields.datetime(
|
||||
'Replied',
|
||||
help='Date when this email has been replied for the first time.'),
|
||||
'bounced': fields.datetime(
|
||||
'Bounced',
|
||||
help='Date when this email has bounced.'
|
||||
),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
|
@ -103,15 +107,24 @@ class mail_mail(osv.Model):
|
|||
return self.write(cr, uid, ids, {'state': 'cancel'}, context=context)
|
||||
|
||||
def set_opened(self, cr, uid, ids, context=None):
|
||||
""" Increment opened counter """
|
||||
""" Set as opened """
|
||||
for mail in self.browse(cr, uid, ids, context=context):
|
||||
self.write(cr, uid, [mail.id], {'opened': (mail.opened + 1)}, context=context)
|
||||
if not mail.opened:
|
||||
self.write(cr, uid, [mail.id], {'opened': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
|
||||
def set_replied(self, cr, uid, ids, context=None):
|
||||
""" Increment replied counter """
|
||||
""" Set as replied """
|
||||
for mail in self.browse(cr, uid, ids, context=context):
|
||||
self.write(cr, uid, [mail.id], {'replied': (mail.replied + 1)}, context=context)
|
||||
if not mail.replied:
|
||||
self.write(cr, uid, [mail.id], {'replied': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
|
||||
def set_bounced(self, cr, uid, ids, context=None):
|
||||
""" Set as bounced """
|
||||
for mail in self.browse(cr, uid, ids, context=context):
|
||||
if not mail.bounced:
|
||||
self.write(cr, uid, [mail.id], {'bounced': fields.datetime.now()}, context=context)
|
||||
return True
|
||||
|
||||
def process_email_queue(self, cr, uid, ids=None, context=None):
|
||||
|
|
|
@ -1426,8 +1426,7 @@ class mail_thread(osv.AbstractModel):
|
|||
# update original mail_mail if exists
|
||||
if type == 'email':
|
||||
mail_mail_ids = self.pool['mail.mail'].search(cr, SUPERUSER_ID, [('mail_message_id', '=', parent_id)], context=context)
|
||||
for mail in self.pool['mail.mail'].browse(cr, SUPERUSER_ID, mail_mail_ids, context=context):
|
||||
self.pool['mail.mail'].write(cr, SUPERUSER_ID, [mail.id], {'replied': mail.replied + 1}, context=context)
|
||||
self.pool['mail.mail'].set_replied(cr, SUPERUSER_ID, mail_mail_ids, context=context)
|
||||
|
||||
message_ids = mail_message.search(cr, SUPERUSER_ID, [('id', '=', parent_id), ('parent_id', '!=', False)], context=context)
|
||||
# avoid loops when finding ancestors
|
||||
|
|
|
@ -19,9 +19,10 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from . import test_mail_group, test_mail_message, test_mail_features, test_mail_gateway, test_message_read, test_invite
|
||||
from . import test_mail_mail, test_mail_group, test_mail_message, test_mail_features, test_mail_gateway, test_message_read, test_invite
|
||||
|
||||
checks = [
|
||||
# test_mail_mail,
|
||||
test_mail_group,
|
||||
test_mail_message,
|
||||
test_mail_features,
|
||||
|
|
|
@ -29,10 +29,16 @@
|
|||
'description': """TODO""",
|
||||
'data': [
|
||||
'mass_mailing_view.xml',
|
||||
'mass_mailing_demo.xml',
|
||||
'mail_mail_view.xml',
|
||||
'wizard/mail_compose_message_view.xml',
|
||||
'security/ir.model.access.csv',
|
||||
],
|
||||
'js': [],
|
||||
'qweb': [],
|
||||
'css': [
|
||||
'static/src/css/mass_mailing.css'
|
||||
],
|
||||
'demo': [],
|
||||
'installable': True,
|
||||
'auto_install': False,
|
||||
|
|
|
@ -28,8 +28,14 @@ class MailMail(osv.Model):
|
|||
_inherit = ['mail.mail']
|
||||
|
||||
_columns = {
|
||||
'mass_mailing_campaign_id': fields.many2one(
|
||||
'mail.mass_mailing.campaign', 'Mass Mailing Campaign',
|
||||
'mass_mailing_segment_id': fields.many2one(
|
||||
'mail.mass_mailing.segment', 'Mass Mailing Segment',
|
||||
ondelete='set null',
|
||||
),
|
||||
'mass_mailing_campaign_id': fields.related(
|
||||
'mass_mailing_segment_id', 'mass_mailing_campaign_id',
|
||||
type='many2one', ondelete='set null',
|
||||
relation='mail.mass_mailing.campaign',
|
||||
store=True, readonly=True,
|
||||
),
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='opened']" position="before">
|
||||
<field name="mass_mailing_campaign_id"/>
|
||||
<field name="mass_mailing_segment_id"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
|
|
@ -19,6 +19,10 @@
|
|||
#
|
||||
##############################################################################
|
||||
|
||||
from datetime import date, datetime
|
||||
from dateutil import relativedelta
|
||||
|
||||
from openerp import tools
|
||||
from openerp.osv import osv, fields
|
||||
|
||||
|
||||
|
@ -32,33 +36,42 @@ class MassMailingCampaign(osv.Model):
|
|||
""" Compute statistics of the mass mailing campaign """
|
||||
results = dict.fromkeys(ids, False)
|
||||
for campaign in self.browse(cr, uid, ids, context=context):
|
||||
if not campaign.mail_ids:
|
||||
results[campaign.id] = {
|
||||
'sent': 0,
|
||||
'opened_ratio': 0.0,
|
||||
'replied_ratio': 0.0,
|
||||
'bounce_ratio': 0.0,
|
||||
}
|
||||
continue
|
||||
results[campaign.id] = {
|
||||
'sent': len(campaign.mail_ids),
|
||||
'opened_ratio': len([mail for mail in campaign.mail_ids if mail.opened]) * 1.0 / len(campaign.mail_ids),
|
||||
'replied_ratio': len([mail for mail in campaign.mail_ids if mail.replied]) * 1.0 / len(campaign.mail_ids),
|
||||
'bounce_ratio': 0.0,
|
||||
'opened': len([mail for mail in campaign.mail_ids if mail.opened]),
|
||||
'replied': len([mail for mail in campaign.mail_ids if mail.replied]),
|
||||
'bounced': len([mail for mail in campaign.mail_ids if mail.bounced]),
|
||||
}
|
||||
return results
|
||||
|
||||
def _get_segment_kanban_ids(self, cr, uid, ids, name, arg, context=None):
|
||||
results = dict.fromkeys(ids, '')
|
||||
for campaign in self.browse(cr, uid, ids, context=context):
|
||||
segment_results = []
|
||||
for segment in campaign.segment_ids:
|
||||
segment_object = {}
|
||||
for attr in ['name', 'sent', 'opened', 'replied', 'bounced']:
|
||||
segment_object[attr] = getattr(segment, attr)
|
||||
segment_results.append(segment_object)
|
||||
results[campaign.id] = segment_results
|
||||
return results
|
||||
|
||||
_columns = {
|
||||
'name': fields.char(
|
||||
'Campaign Name', required=True,
|
||||
),
|
||||
'template_id': fields.many2one(
|
||||
'email.template', 'Email Template',
|
||||
ondelete='set null',
|
||||
'segment_ids': fields.one2many(
|
||||
'mail.mass_mailing.segment', 'mass_mailing_campaign_id',
|
||||
'Segments',
|
||||
),
|
||||
'segment_kanban_ids': fields.function(
|
||||
_get_segment_kanban_ids,
|
||||
type='text', string='Segments (kanban data)',
|
||||
help='This field has for purpose to gather data about segment to display them in kanban view as nested kanban views is not possible currently',
|
||||
),
|
||||
'mail_ids': fields.one2many(
|
||||
'mail.mail', 'mass_mailing_campaign_id',
|
||||
'Send Emails',
|
||||
'Sent Emails',
|
||||
),
|
||||
# stat fields
|
||||
'sent': fields.function(
|
||||
|
@ -66,19 +79,132 @@ class MassMailingCampaign(osv.Model):
|
|||
string='Sent Emails',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
'opened_ratio': fields.function(
|
||||
'opened': fields.function(
|
||||
_get_statistics,
|
||||
string='Opened Ratio',
|
||||
type='float', multi='_get_statistics',
|
||||
string='Opened',
|
||||
type='integer', multi='_get_statistics',
|
||||
),
|
||||
'replied_ratio': fields.function(
|
||||
'replied': fields.function(
|
||||
_get_statistics,
|
||||
string='Replied Ratio',
|
||||
type='float', multi='_get_statistics'
|
||||
string='Replied',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
'bounce_ratio': fields.function(
|
||||
'bounced': fields.function(
|
||||
_get_statistics,
|
||||
string='Bounce Ratio',
|
||||
type='float', multi='_get_statistics'
|
||||
string='Bounced',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
class MassMailingSegment(osv.Model):
|
||||
""" TODO """
|
||||
_name = 'mail.mass_mailing.segment'
|
||||
_description = 'Segment of a mass mailing campaign'
|
||||
# number of periods for tracking mail_mail statistics
|
||||
_period_number = 6
|
||||
|
||||
def __get_bar_values(self, cr, uid, obj, domain, read_fields, value_field, groupby_field, context=None):
|
||||
""" Generic method to generate data for bar chart values using SparklineBarWidget.
|
||||
This method performs obj.read_group(cr, uid, domain, read_fields, groupby_field).
|
||||
|
||||
:param obj: the target model (i.e. crm_lead)
|
||||
:param domain: the domain applied to the read_group
|
||||
:param list read_fields: the list of fields to read in the read_group
|
||||
:param str value_field: the field used to compute the value of the bar slice
|
||||
:param str groupby_field: the fields used to group
|
||||
|
||||
:return list section_result: a list of dicts: [
|
||||
{ 'value': (int) bar_column_value,
|
||||
'tootip': (str) bar_column_tooltip,
|
||||
}
|
||||
]
|
||||
"""
|
||||
month_begin = date.today().replace(day=1)
|
||||
section_result = [{'value': 0,
|
||||
'tooltip': (month_begin + relativedelta.relativedelta(months=-i)).strftime('%B'),
|
||||
} for i in range(self._period_number - 1, -1, -1)]
|
||||
group_obj = obj.read_group(cr, uid, domain, read_fields, groupby_field, context=context)
|
||||
print group_obj
|
||||
for group in group_obj:
|
||||
group_begin_date = datetime.strptime(group['__domain'][0][2], tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
month_delta = relativedelta.relativedelta(month_begin, group_begin_date)
|
||||
section_result[self._period_number - (month_delta.months + 1)] = {'value': group.get(value_field, 0), 'tooltip': group_begin_date.strftime('%B')}
|
||||
return section_result
|
||||
|
||||
def _get_monthly_statistics(self, cr, uid, ids, field_name, arg, context=None):
|
||||
""" TODO
|
||||
"""
|
||||
obj = self.pool.get('mail.mail')
|
||||
res = dict.fromkeys(ids, False)
|
||||
month_begin = date.today().replace(day=1)
|
||||
groupby_begin = (month_begin + relativedelta.relativedelta(months=-4)).strftime(tools.DEFAULT_SERVER_DATE_FORMAT)
|
||||
for id in ids:
|
||||
res[id] = dict()
|
||||
domain = [('mass_mailing_segment_id', '=', id), ('opened', '>=', groupby_begin)]
|
||||
res[id]['opened_monthly'] = self.__get_bar_values(cr, uid, obj, domain, ['opened'], 'opened_count', 'opened', context=context)
|
||||
domain = [('mass_mailing_segment_id', '=', id), ('replied', '>=', groupby_begin)]
|
||||
res[id]['replied_monthly'] = self.__get_bar_values(cr, uid, obj, domain, ['replied'], 'replied_count', 'replied', context=context)
|
||||
return res
|
||||
|
||||
def _get_statistics(self, cr, uid, ids, name, arg, context=None):
|
||||
""" Compute statistics of the mass mailing campaign """
|
||||
results = dict.fromkeys(ids, False)
|
||||
for segment in self.browse(cr, uid, ids, context=context):
|
||||
results[segment.id] = {
|
||||
'sent': len(segment.mail_ids),
|
||||
'opened': len([mail for mail in segment.mail_ids if mail.opened]),
|
||||
'replied': len([mail for mail in segment.mail_ids if mail.replied]),
|
||||
'bounced': len([mail for mail in segment.mail_ids if mail.bounced]),
|
||||
}
|
||||
return results
|
||||
|
||||
_columns = {
|
||||
'name': fields.char('Name', required=True),
|
||||
'mass_mailing_campaign_id': fields.many2one(
|
||||
'mail.mass_mailing.campaign', 'Mass Mailing Campaign',
|
||||
ondelete='cascade',
|
||||
),
|
||||
'template_id': fields.many2one(
|
||||
'email.template', 'Email Template',
|
||||
ondelete='set null',
|
||||
),
|
||||
'domain': fields.char('Domain'),
|
||||
'date': fields.datetime('Date'),
|
||||
# mail_mail data
|
||||
'mail_ids': fields.one2many(
|
||||
'mail.mail', 'mass_mailing_segment_id',
|
||||
'Send Emails',
|
||||
),
|
||||
'sent': fields.function(
|
||||
_get_statistics,
|
||||
string='Sent Emails',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
'opened': fields.function(
|
||||
_get_statistics,
|
||||
string='Opened',
|
||||
type='integer', multi='_get_statistics',
|
||||
),
|
||||
'replied': fields.function(
|
||||
_get_statistics,
|
||||
string='Replied',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
'bounced': fields.function(
|
||||
_get_statistics,
|
||||
string='Bounce',
|
||||
type='integer', multi='_get_statistics'
|
||||
),
|
||||
# monthly ratio
|
||||
'opened_monthly': fields.function(
|
||||
_get_monthly_statistics,
|
||||
string='Sent Emails',
|
||||
type='char', multi='_get_monthly_statistics',
|
||||
),
|
||||
'replied_monthly': fields.function(
|
||||
_get_monthly_statistics,
|
||||
string='Replied',
|
||||
type='char', multi='_get_monthly_statistics',
|
||||
),
|
||||
}
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
<?xml version="1.0"?>
|
||||
<openerp>
|
||||
<!-- <data noupdate="1"> -->
|
||||
<data>
|
||||
|
||||
<record id="mass_mail_template_1" model="email.template">
|
||||
<field name="name">Partner Newsletter 1</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="auto_delete" eval="False"/>
|
||||
<field name="partner_to">${object.id}</field>
|
||||
<field name="body_html"><![CDATA[<p>Hello</p>]]></field>
|
||||
</record>
|
||||
<record id="mass_mail_template_2" model="email.template">
|
||||
<field name="name">Partner Newsletter 2</field>
|
||||
<field name="model_id" ref="base.model_res_partner"/>
|
||||
<field name="auto_delete" eval="False"/>
|
||||
<field name="partner_to">${object.id}</field>
|
||||
<field name="body_html"><![CDATA[<p>Hello</p>]]></field>
|
||||
</record>
|
||||
|
||||
<record id="mass_mail_campaign_1" model="mail.mass_mailing.campaign">
|
||||
<field name="name">Partners Newsletter</field>
|
||||
</record>
|
||||
|
||||
<record id="mass_mail_segment_1" model="mail.mass_mailing.segment">
|
||||
<field name="name">First Newsletter</field>
|
||||
<field name="template_id" eval="ref('mass_mail_template_1')"/>
|
||||
<field name="date" eval="(DateTime.today() - relativedelta(month=2)).replace(day=1)"/>
|
||||
<field name="mass_mailing_campaign_id" eval="ref('mass_mail_campaign_1')"/>
|
||||
</record>
|
||||
<record id="mass_mail_segment_2" model="mail.mass_mailing.segment">
|
||||
<field name="name">Second Newsletter</field>
|
||||
<field name="template_id" eval="ref('mass_mail_template_2')"/>
|
||||
<field name="date" eval="(DateTime.today() - relativedelta(month=1)).replace(day=1)"/>
|
||||
<field name="mass_mailing_campaign_id" eval="ref('mass_mail_campaign_1')"/>
|
||||
</record>
|
||||
|
||||
<record id="mass_mail_email_1" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
|
||||
<field name="opened" eval="(DateTime.today() - relativedelta(days=15)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="replied" eval="(DateTime.today() - relativedelta(days=10)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_2" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
|
||||
<field name="opened" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="replied" eval="(DateTime.today() - relativedelta(days=0)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_3" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
|
||||
<field name="opened" eval="(DateTime.today() - relativedelta(days=0)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_4" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_5" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_1')"/>
|
||||
<field name="bounced" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
|
||||
<record id="mass_mail_email_2_1" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_2')"/>
|
||||
<field name="opened" eval="(DateTime.today() - relativedelta(days=15)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_2_2" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_2')"/>
|
||||
<field name="opened" eval="(DateTime.today() - relativedelta(days=5)).strftime('%Y-%m-%d %H:%M')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
<record id="mass_mail_email_2_3" model="mail.mail">
|
||||
<field name="mass_mailing_segment_id" eval="ref('mass_mail_segment_2')"/>
|
||||
<field name="state">sent</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</openerp>
|
|
@ -3,7 +3,7 @@
|
|||
<data>
|
||||
|
||||
<!-- MASS MAILING CAMPAIGNS !-->
|
||||
<record model="ir.ui.view" id="view_followers_tree">
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_campaign_tree">
|
||||
<field name="name">mail.mass_mailing.campaign.tree</field>
|
||||
<field name="model">mail.mass_mailing.campaign</field>
|
||||
<field name="priority">10</field>
|
||||
|
@ -14,7 +14,7 @@
|
|||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_subscription_form">
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_campaign_form">
|
||||
<field name="name">mail.mass_mailing.campaign.form</field>
|
||||
<field name="model">mail.mass_mailing.campaign</field>
|
||||
<field name="arch" type="xml">
|
||||
|
@ -22,27 +22,188 @@
|
|||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="template_id"/>
|
||||
<field name="sent"/>
|
||||
<field name="opened_ratio"/>
|
||||
<field name="replied_ratio"/>
|
||||
<field name="bounce_ratio"/>
|
||||
<field name="opened"/>
|
||||
<field name="replied"/>
|
||||
<field name="bounced"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- CRM Lead Kanban View -->
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_campaign_kanban">
|
||||
<field name="name">mail.mass_mailing.campaign.kanban</field>
|
||||
<field name="model">mail.mass_mailing.campaign</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban>
|
||||
<field name="segment_kanban_ids"/>
|
||||
<field name='sent'/>
|
||||
<templates>
|
||||
<t t-name="mass_mailing.segment">
|
||||
<div>
|
||||
<h4><t t-raw="segment.name"/></h4>
|
||||
</div>
|
||||
<div>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><t t-raw="segment.sent"/></span><br />
|
||||
Sent
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><t t-raw="segment.opened"/></span><br />
|
||||
Opened
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><t t-raw="segment.replied"/></span><br />
|
||||
Replied
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><t t-raw="segment.bounced"/></span><br />
|
||||
Bounced
|
||||
</p>
|
||||
</div>
|
||||
</t>
|
||||
<t t-name="kanban-box">
|
||||
<!-- <div t-attf-class="oe_kanban_color_#{kanban_getcolor(record.color.raw_value)} oe_kanban_card oe_kanban_global_click"> -->
|
||||
<div t-attf-class="oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing oe_kanban_mass_mailing_campaign">
|
||||
<div class="oe_kanban_content">
|
||||
<h3>
|
||||
<field name="name"/>
|
||||
</h3>
|
||||
<div>
|
||||
<field name="opened" widget="gauge" style="width:120px; height: 80px;"
|
||||
options="{'max_field': 'sent'}"/>
|
||||
<field name="replied" widget="gauge" style="width:120px; height: 80px;"
|
||||
options="{'max_field': 'sent'}"/>
|
||||
</div>
|
||||
<t t-foreach='record.segment_kanban_ids.value' t-as='segment'>
|
||||
<t t-call="mass_mailing.segment"/>
|
||||
</t>
|
||||
</div>
|
||||
<div class="oe_clear"></div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_mass_mailing_campaigns" model="ir.actions.act_window">
|
||||
<field name="name">Mass Mailing Campaigns</field>
|
||||
<field name="res_model">mail.mass_mailing.campaign</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_mode">kanban,tree,form</field>
|
||||
</record>
|
||||
|
||||
<!-- MASS MAILING SEGMENTS !-->
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_segment_tree">
|
||||
<field name="name">mail.mass_mailing.segment.tree</field>
|
||||
<field name="model">mail.mass_mailing.segment</field>
|
||||
<field name="priority">10</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Mass Mailing Segments">
|
||||
<field name="name"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_segment_form">
|
||||
<field name="name">mail.mass_mailing.segment.form</field>
|
||||
<field name="model">mail.mass_mailing.segment</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Mass Mailing Campaign" version="7.0">
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name"/>
|
||||
<field name="mass_mailing_campaign_id"/>
|
||||
<field name="date"/>
|
||||
<field name="template_id"/>
|
||||
</group>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_mail_mass_mailing_segment_kanban">
|
||||
<field name="name">mail.mass_mailing.segment.kanban</field>
|
||||
<field name="model">mail.mass_mailing.segment</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban>
|
||||
<templates>
|
||||
<t t-name="kanban-box">
|
||||
<div t-attf-class="oe_kanban_card oe_kanban_global_click oe_kanban_mass_mailing oe_kanban_mass_mailing_segment">
|
||||
<div class="oe_kanban_content">
|
||||
<div>
|
||||
<h3>
|
||||
<field name="name"/>
|
||||
</h3>
|
||||
<p style="margin-left: 10px; margin-top: 8px;">
|
||||
Sent: <field name="date"/><br />
|
||||
Campaign: <field name="mass_mailing_campaign_id"/>
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><field name="sent"/></span><br />
|
||||
Sent
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><field name="opened"/></span><br />
|
||||
Opened
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><field name="replied"/></span><br />
|
||||
Replied
|
||||
</p>
|
||||
<p class="oe_mail_stats">
|
||||
<span class="oe_mail_result"><field name="bounced"/></span><br />
|
||||
Bounced
|
||||
</p>
|
||||
</div>
|
||||
<div>
|
||||
<div class="oe_sparkline_container">
|
||||
<h4 class="oe_sparkline_bar_title">Opened</h4><br />
|
||||
<field name="opened_monthly" widget="sparkline_bar" height="50px" barWidth="10px" barSpacing="15px"/>
|
||||
</div>
|
||||
<div class="oe_sparkline_container">
|
||||
<h4 class="oe_sparkline_bar_title">Replied</h4><br />
|
||||
<field name="replied_monthly" widget="sparkline_bar" height="50px" barWidth="10px" barSpacing="15px"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="oe_clear"></div>
|
||||
</div>
|
||||
</t>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_mass_mailing_segments" model="ir.actions.act_window">
|
||||
<field name="name">Mass Mailing Segments</field>
|
||||
<field name="res_model">mail.mass_mailing.segment</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">kanban,tree,form</field>
|
||||
</record>
|
||||
|
||||
<!-- Add followers related menu entries in Settings/Email -->
|
||||
<menuitem name="Mass mailing campaigns" id="menu_email_campaigns" parent="base.menu_email"
|
||||
action="action_view_mass_mailing_campaigns" sequence="60" groups="base.group_no_one"/>
|
||||
|
||||
<!-- Top menu item -->
|
||||
<menuitem name="Marketing" id="base.marketing_menu" sequence="85"/>
|
||||
|
||||
<!-- Add in marketing -->
|
||||
<menuitem name="Mass Mailing Campaign" id="mass_mailing_campaign"
|
||||
parent="base.marketing_menu" sequence="1"/>
|
||||
<menuitem name="Campaigns" id="menu_email_campaigns"
|
||||
parent="mass_mailing_campaign" sequence="1"
|
||||
action="action_view_mass_mailing_campaigns"/>
|
||||
<menuitem name="Segments" id="menu_email_segments"
|
||||
parent="mass_mailing_campaign" sequence="2"
|
||||
action="action_view_mass_mailing_segments"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_campaign {
|
||||
width: 270px;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing.oe_kanban_mass_mailing_segment {
|
||||
width: 270px;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_mail_stats {
|
||||
width: 120px;
|
||||
display: inline-block;
|
||||
margin: 2px 5px 0px 5px;
|
||||
text-align: center;
|
||||
border: 1px solid rgba(0, 0, 0, 0.16);
|
||||
-webkit-border-radius: 2px;
|
||||
border-radius: 2px;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_mail_result {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_gauge {
|
||||
width: 120px;
|
||||
height: 120px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_kanban_content div.oe_sparkline_container {
|
||||
height: 60px;
|
||||
width: 120px;
|
||||
display: inline-block;
|
||||
margin: 8px 5px 0px 5px;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_sparkline_bar_title {
|
||||
text-align: center;
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.openerp .oe_kanban_view .oe_kanban_mass_mailing .oe_sparkline_bar {
|
||||
width: 100px;
|
||||
height: 60px;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
/*
|
||||
* Campaign related CSS
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
* Segment related CSS
|
||||
*/
|
|
@ -48,7 +48,6 @@ modules.
|
|||
'report/sale_crm_account_invoice_report_view.xml',
|
||||
],
|
||||
'js': [
|
||||
'static/lib/justgage.js',
|
||||
'static/src/js/sale_crm.js',
|
||||
],
|
||||
'demo': ['sale_crm_demo.xml'],
|
||||
|
|
|
@ -268,8 +268,8 @@
|
|||
</xpath>
|
||||
<xpath expr="//div[@class='oe_items_list']" position="after">
|
||||
<div class="oe_center" t-if="record.invoiced_target.raw_value">
|
||||
<field name="monthly_invoiced" widget="gage" style="width:160px; height: 120px;" options="{'max_field': 'invoiced_target'}">Invoiced</field>
|
||||
<field name="invoiced_forecast" widget="gage" style="width:160px; height: 120px;" options="{'max_field': 'invoiced_target', 'action_change': 'action_forecast'}">Forecast</field>
|
||||
<field name="monthly_invoiced" widget="gauge" style="width:160px; height: 120px;" options="{'max_field': 'invoiced_target'}">Invoiced</field>
|
||||
<field name="invoiced_forecast" widget="gauge" style="width:160px; height: 120px;" options="{'max_field': 'invoiced_target', 'action_change': 'action_forecast'}">Forecast</field>
|
||||
</div>
|
||||
<div class="oe_center" style="color:#bbbbbb;" t-if="!record.invoiced_target.raw_value">
|
||||
<br/>Define an invoicing target in the sales team settings to see the period's achievement and forecast at a glance.
|
||||
|
|
|
@ -1,883 +0,0 @@
|
|||
/**
|
||||
* JustGage - this is work-in-progress, unreleased, unofficial code, so it might not work top-notch :)
|
||||
* Check http://www.justgage.com for official releases
|
||||
* Licensed under MIT.
|
||||
* @author Bojan Djuricic (@Toorshia)
|
||||
*
|
||||
* LATEST UPDATES
|
||||
|
||||
* -----------------------------
|
||||
* April 01, 2013.
|
||||
* -----------------------------
|
||||
* fix - https://github.com/toorshia/justgage/issues/46
|
||||
|
||||
* -----------------------------
|
||||
* March 26, 2013.
|
||||
* -----------------------------
|
||||
* customSectors - define specific color for value range (0-10 : red, 10-30 : blue etc.)
|
||||
|
||||
* -----------------------------
|
||||
* March 23, 2013.
|
||||
* -----------------------------
|
||||
* counter - option to animate value in counting fashion
|
||||
* fix - https://github.com/toorshia/justgage/issues/45
|
||||
|
||||
* -----------------------------
|
||||
* March 13, 2013.
|
||||
* -----------------------------
|
||||
* refresh method - added optional 'max' parameter to use when you need to update max value
|
||||
|
||||
* -----------------------------
|
||||
* February 26, 2013.
|
||||
* -----------------------------
|
||||
* decimals - option to define/limit number of decimals when not using humanFriendly or customRenderer to display value
|
||||
* fixed a missing parameters bug when calling generateShadow() for IE < 9
|
||||
|
||||
* -----------------------------
|
||||
* December 31, 2012.
|
||||
* -----------------------------
|
||||
* fixed text y-position for hidden divs - workaround for Raphael <tspan> 'dy' bug - https://github.com/DmitryBaranovskiy/raphael/issues/491
|
||||
* 'show' parameters, like showMinMax are now 'hide' because I am lame developer - please update these in your setups
|
||||
* Min and Max labels are now auto-off when in donut mode
|
||||
* Start angle in donut mode is now 90
|
||||
* donutStartAngle - option to define start angle for donut
|
||||
|
||||
* -----------------------------
|
||||
* November 25, 2012.
|
||||
* -----------------------------
|
||||
* Option to define custom rendering function for displayed value
|
||||
|
||||
* -----------------------------
|
||||
* November 19, 2012.
|
||||
* -----------------------------
|
||||
* Config.value is now updated after gauge refresh
|
||||
|
||||
* -----------------------------
|
||||
* November 13, 2012.
|
||||
* -----------------------------
|
||||
* Donut display mode added
|
||||
* Option to hide value label
|
||||
* Option to enable responsive gauge size
|
||||
* Removed default title attribute
|
||||
* Option to accept min and max defined as string values
|
||||
* Option to configure value symbol
|
||||
* Fixed bad aspect ratio calculations
|
||||
* Option to configure minimum font size for all texts
|
||||
* Option to show shorthand big numbers (human friendly)
|
||||
*/
|
||||
|
||||
JustGage = function(config) {
|
||||
|
||||
if (!config.id) {alert("Missing id parameter for gauge!"); return false;}
|
||||
if (!config.node) {
|
||||
if (!document.getElementById(config.id)) {alert("No element with id: \""+config.id+"\" found!"); return false;}
|
||||
config.node = document.getElementById(config.id);
|
||||
}
|
||||
|
||||
var obj = this;
|
||||
|
||||
// configurable parameters
|
||||
obj.config =
|
||||
{
|
||||
// id : string
|
||||
// this is container element id
|
||||
id : config.id,
|
||||
|
||||
// node : string
|
||||
// the node to use instead of DOM
|
||||
node : config.node,
|
||||
|
||||
// title : string
|
||||
// gauge title
|
||||
title : (config.title) ? config.title : "",
|
||||
|
||||
// titleFontColor : string
|
||||
// color of gauge title
|
||||
titleFontColor : (config.titleFontColor) ? config.titleFontColor : "#999999",
|
||||
|
||||
// value : int
|
||||
// value gauge is showing
|
||||
value : (config.value) ? config.value : 0,
|
||||
|
||||
|
||||
// valueFontColor : string
|
||||
// color of label showing current value
|
||||
valueFontColor : (config.valueFontColor) ? config.valueFontColor : "#010101",
|
||||
|
||||
// symbol : string
|
||||
// special symbol to show next to value
|
||||
symbol : (config.symbol) ? config.symbol : "",
|
||||
|
||||
// min : int
|
||||
// min value
|
||||
min : (config.min) ? parseFloat(config.min) : 0,
|
||||
|
||||
// max : int
|
||||
// max value
|
||||
max : (config.max) ? parseFloat(config.max) : 100,
|
||||
|
||||
// humanFriendlyDecimal : int
|
||||
// number of decimal places for our human friendly number to contain
|
||||
humanFriendlyDecimal : (config.humanFriendlyDecimal) ? config.humanFriendlyDecimal : 0,
|
||||
|
||||
// textRenderer: func
|
||||
// function applied before rendering text
|
||||
textRenderer : (config.textRenderer) ? config.textRenderer : null,
|
||||
|
||||
// gaugeWidthScale : float
|
||||
// width of the gauge element
|
||||
gaugeWidthScale : (config.gaugeWidthScale) ? config.gaugeWidthScale : 1.0,
|
||||
|
||||
// gaugeColor : string
|
||||
// background color of gauge element
|
||||
gaugeColor : (config.gaugeColor) ? config.gaugeColor : "#edebeb",
|
||||
|
||||
// label : string
|
||||
// text to show below value
|
||||
label : (config.label) ? config.label : "",
|
||||
|
||||
// labelFontColor : string
|
||||
// color of label showing label under value
|
||||
labelFontColor : (config.labelFontColor) ? config.labelFontColor : "#b3b3b3",
|
||||
|
||||
// shadowOpacity : int
|
||||
// 0 ~ 1
|
||||
shadowOpacity : (config.shadowOpacity) ? config.shadowOpacity : 0.2,
|
||||
|
||||
// shadowSize: int
|
||||
// inner shadow size
|
||||
shadowSize : (config.shadowSize) ? config.shadowSize : 5,
|
||||
|
||||
// shadowVerticalOffset : int
|
||||
// how much shadow is offset from top
|
||||
shadowVerticalOffset : (config.shadowVerticalOffset) ? config.shadowVerticalOffset : 3,
|
||||
|
||||
// levelColors : string[]
|
||||
// colors of indicator, from lower to upper, in RGB format
|
||||
levelColors : (config.levelColors) ? config.levelColors : [
|
||||
"#a9d70b",
|
||||
"#f9c802",
|
||||
"#ff0000"
|
||||
],
|
||||
|
||||
// startAnimationTime : int
|
||||
// length of initial animation
|
||||
startAnimationTime : (config.startAnimationTime) ? config.startAnimationTime : 700,
|
||||
|
||||
// startAnimationType : string
|
||||
// type of initial animation (linear, >, <, <>, bounce)
|
||||
startAnimationType : (config.startAnimationType) ? config.startAnimationType : ">",
|
||||
|
||||
// refreshAnimationTime : int
|
||||
// length of refresh animation
|
||||
refreshAnimationTime : (config.refreshAnimationTime) ? config.refreshAnimationTime : 700,
|
||||
|
||||
// refreshAnimationType : string
|
||||
// type of refresh animation (linear, >, <, <>, bounce)
|
||||
refreshAnimationType : (config.refreshAnimationType) ? config.refreshAnimationType : ">",
|
||||
|
||||
// donutStartAngle : int
|
||||
// angle to start from when in donut mode
|
||||
donutStartAngle : (config.donutStartAngle) ? config.donutStartAngle : 90,
|
||||
|
||||
// valueMinFontSize : int
|
||||
// absolute minimum font size for the value
|
||||
valueMinFontSize : config.valueMinFontSize || 16,
|
||||
|
||||
// titleMinFontSize
|
||||
// absolute minimum font size for the title
|
||||
titleMinFontSize : config.titleMinFontSize || 10,
|
||||
|
||||
// labelMinFontSize
|
||||
// absolute minimum font size for the label
|
||||
labelMinFontSize : config.labelMinFontSize || 10,
|
||||
|
||||
// minLabelMinFontSize
|
||||
// absolute minimum font size for the minimum label
|
||||
minLabelMinFontSize : config.minLabelMinFontSize || 10,
|
||||
|
||||
// maxLabelMinFontSize
|
||||
// absolute minimum font size for the maximum label
|
||||
maxLabelMinFontSize : config.maxLabelMinFontSize || 10,
|
||||
|
||||
// hideValue : bool
|
||||
// hide value text
|
||||
hideValue : (config.hideValue) ? config.hideValue : false,
|
||||
|
||||
// hideMinMax : bool
|
||||
// hide min and max values
|
||||
hideMinMax : (config.hideMinMax) ? config.hideMinMax : false,
|
||||
|
||||
// hideInnerShadow : bool
|
||||
// hide inner shadow
|
||||
hideInnerShadow : (config.hideInnerShadow) ? config.hideInnerShadow : false,
|
||||
|
||||
// humanFriendly : bool
|
||||
// convert large numbers for min, max, value to human friendly (e.g. 1234567 -> 1.23M)
|
||||
humanFriendly : (config.humanFriendly) ? config.humanFriendly : false,
|
||||
|
||||
// noGradient : bool
|
||||
// whether to use gradual color change for value, or sector-based
|
||||
noGradient : (config.noGradient) ? config.noGradient : false,
|
||||
|
||||
// donut : bool
|
||||
// show full donut gauge
|
||||
donut : (config.donut) ? config.donut : false,
|
||||
|
||||
// relativeGaugeSize : bool
|
||||
// whether gauge size should follow changes in container element size
|
||||
relativeGaugeSize : (config.relativeGaugeSize) ? config.relativeGaugeSize : false,
|
||||
|
||||
// counter : bool
|
||||
// animate level number change
|
||||
counter : (config.counter) ? config.counter : false,
|
||||
|
||||
// decimals : int
|
||||
// number of digits after floating point
|
||||
decimals : (config.decimals) ? config.decimals : 0,
|
||||
|
||||
// customSectors : [] of objects
|
||||
// number of digits after floating point
|
||||
customSectors : (config.customSectors) ? config.customSectors : []
|
||||
};
|
||||
|
||||
// variables
|
||||
var
|
||||
canvasW,
|
||||
canvasH,
|
||||
widgetW,
|
||||
widgetH,
|
||||
aspect,
|
||||
dx,
|
||||
dy,
|
||||
titleFontSize,
|
||||
titleX,
|
||||
titleY,
|
||||
valueFontSize,
|
||||
valueX,
|
||||
valueY,
|
||||
labelFontSize,
|
||||
labelX,
|
||||
labelY,
|
||||
minFontSize,
|
||||
minX,
|
||||
minY,
|
||||
maxFontSize,
|
||||
maxX,
|
||||
maxY;
|
||||
|
||||
// overflow values
|
||||
if (this.config.value > this.config.max) this.config.value = this.config.max;
|
||||
if (this.config.value < this.config.min) this.config.value = this.config.min;
|
||||
this.originalValue = config.value;
|
||||
|
||||
// canvas
|
||||
this.canvas = Raphael(this.config.node, "100%", "100%");
|
||||
if (this.config.relativeGaugeSize === true) {
|
||||
this.canvas.setViewBox(0, 0, 200, 150, true);
|
||||
}
|
||||
|
||||
// canvas dimensions
|
||||
if (this.config.relativeGaugeSize === true) {
|
||||
canvasW = 200;
|
||||
canvasH = 150;
|
||||
} else {
|
||||
canvasW = getStyle(this.config.node, "width").slice(0, -2) * 1;
|
||||
canvasH = getStyle(this.config.node, "height").slice(0, -2) * 1;
|
||||
}
|
||||
|
||||
// widget dimensions
|
||||
if (this.config.donut === true) {
|
||||
|
||||
// DONUT *******************************
|
||||
|
||||
// width more than height
|
||||
if(canvasW > canvasH) {
|
||||
widgetH = canvasH;
|
||||
widgetW = widgetH;
|
||||
// width less than height
|
||||
} else if (canvasW < canvasH) {
|
||||
widgetW = canvasW;
|
||||
widgetH = widgetW;
|
||||
// if height don't fit, rescale both
|
||||
if(widgetH > canvasH) {
|
||||
aspect = widgetH / canvasH;
|
||||
widgetH = widgetH / aspect;
|
||||
widgetW = widgetH / aspect;
|
||||
}
|
||||
// equal
|
||||
} else {
|
||||
widgetW = canvasW;
|
||||
widgetH = widgetW;
|
||||
}
|
||||
|
||||
// delta
|
||||
dx = (canvasW - widgetW)/2;
|
||||
dy = (canvasH - widgetH)/2;
|
||||
|
||||
// title
|
||||
titleFontSize = ((widgetH / 8) > 10) ? (widgetH / 10) : 10;
|
||||
titleX = dx + widgetW / 2;
|
||||
titleY = dy + widgetH / 11;
|
||||
|
||||
// value
|
||||
valueFontSize = ((widgetH / 6.4) > 16) ? (widgetH / 5.4) : 18;
|
||||
valueX = dx + widgetW / 2;
|
||||
if(this.config.label !== '') {
|
||||
valueY = dy + widgetH / 1.85;
|
||||
} else {
|
||||
valueY = dy + widgetH / 1.7;
|
||||
}
|
||||
|
||||
// label
|
||||
labelFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10;
|
||||
labelX = dx + widgetW / 2;
|
||||
labelY = valueY + labelFontSize;
|
||||
|
||||
// min
|
||||
minFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10;
|
||||
minX = dx + (widgetW / 10) + (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ;
|
||||
minY = labelY;
|
||||
|
||||
// max
|
||||
maxFontSize = ((widgetH / 16) > 10) ? (widgetH / 16) : 10;
|
||||
maxX = dx + widgetW - (widgetW / 10) - (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ;
|
||||
maxY = labelY;
|
||||
|
||||
} else {
|
||||
// HALF *******************************
|
||||
|
||||
// width more than height
|
||||
if(canvasW > canvasH) {
|
||||
widgetH = canvasH;
|
||||
widgetW = widgetH * 1.25;
|
||||
//if width doesn't fit, rescale both
|
||||
if(widgetW > canvasW) {
|
||||
aspect = widgetW / canvasW;
|
||||
widgetW = widgetW / aspect;
|
||||
widgetH = widgetH / aspect;
|
||||
}
|
||||
// width less than height
|
||||
} else if (canvasW < canvasH) {
|
||||
widgetW = canvasW;
|
||||
widgetH = widgetW / 1.25;
|
||||
// if height don't fit, rescale both
|
||||
if(widgetH > canvasH) {
|
||||
aspect = widgetH / canvasH;
|
||||
widgetH = widgetH / aspect;
|
||||
widgetW = widgetH / aspect;
|
||||
}
|
||||
// equal
|
||||
} else {
|
||||
widgetW = canvasW;
|
||||
widgetH = widgetW * 0.75;
|
||||
}
|
||||
|
||||
// delta
|
||||
dx = (canvasW - widgetW)/2;
|
||||
dy = (canvasH - widgetH)/2;
|
||||
|
||||
// title
|
||||
titleFontSize = ((widgetH / 8) > this.config.titleMinFontSize) ? (widgetH / 10) : this.config.titleMinFontSize;
|
||||
titleX = dx + widgetW / 2;
|
||||
titleY = dy + widgetH / 6.4;
|
||||
|
||||
// value
|
||||
valueFontSize = ((widgetH / 6.5) > this.config.valueMinFontSize) ? (widgetH / 6.5) : this.config.valueMinFontSize;
|
||||
valueX = dx + widgetW / 2;
|
||||
valueY = dy + widgetH / 1.275;
|
||||
|
||||
// label
|
||||
labelFontSize = ((widgetH / 16) > this.config.labelMinFontSize) ? (widgetH / 16) : this.config.labelMinFontSize;
|
||||
labelX = dx + widgetW / 2;
|
||||
labelY = valueY + valueFontSize / 2 + 5;
|
||||
|
||||
// min
|
||||
minFontSize = ((widgetH / 16) > this.config.minLabelMinFontSize) ? (widgetH / 16) : this.config.minLabelMinFontSize;
|
||||
minX = dx + (widgetW / 10) + (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ;
|
||||
minY = labelY;
|
||||
|
||||
// max
|
||||
maxFontSize = ((widgetH / 16) > this.config.maxLabelMinFontSize) ? (widgetH / 16) : this.config.maxLabelMinFontSize;
|
||||
maxX = dx + widgetW - (widgetW / 10) - (widgetW / 6.666666666666667 * this.config.gaugeWidthScale) / 2 ;
|
||||
maxY = labelY;
|
||||
}
|
||||
|
||||
// parameters
|
||||
this.params = {
|
||||
canvasW : canvasW,
|
||||
canvasH : canvasH,
|
||||
widgetW : widgetW,
|
||||
widgetH : widgetH,
|
||||
dx : dx,
|
||||
dy : dy,
|
||||
titleFontSize : titleFontSize,
|
||||
titleX : titleX,
|
||||
titleY : titleY,
|
||||
valueFontSize : valueFontSize,
|
||||
valueX : valueX,
|
||||
valueY : valueY,
|
||||
labelFontSize : labelFontSize,
|
||||
labelX : labelX,
|
||||
labelY : labelY,
|
||||
minFontSize : minFontSize,
|
||||
minX : minX,
|
||||
minY : minY,
|
||||
maxFontSize : maxFontSize,
|
||||
maxX : maxX,
|
||||
maxY : maxY
|
||||
};
|
||||
|
||||
// var clear
|
||||
canvasW, canvasH, widgetW, widgetH, aspect, dx, dy, titleFontSize, titleX, titleY, valueFontSize, valueX, valueY, labelFontSize, labelX, labelY, minFontSize, minX, minY, maxFontSize, maxX, maxY = null
|
||||
|
||||
// pki - custom attribute for generating gauge paths
|
||||
this.canvas.customAttributes.pki = function (value, min, max, w, h, dx, dy, gws, donut) {
|
||||
|
||||
var alpha, Ro, Ri, Cx, Cy, Xo, Yo, Xi, Yi, path;
|
||||
|
||||
if (donut) {
|
||||
alpha = (1 - 2 * (value - min) / (max - min)) * Math.PI;
|
||||
Ro = w / 2 - w / 7;
|
||||
Ri = Ro - w / 6.666666666666667 * gws;
|
||||
|
||||
Cx = w / 2 + dx;
|
||||
Cy = h / 1.95 + dy;
|
||||
|
||||
Xo = w / 2 + dx + Ro * Math.cos(alpha);
|
||||
Yo = h - (h - Cy) + 0 - Ro * Math.sin(alpha);
|
||||
Xi = w / 2 + dx + Ri * Math.cos(alpha);
|
||||
Yi = h - (h - Cy) + 0 - Ri * Math.sin(alpha);
|
||||
|
||||
path += "M" + (Cx - Ri) + "," + Cy + " ";
|
||||
path += "L" + (Cx - Ro) + "," + Cy + " ";
|
||||
if (value > ((max - min) / 2)) {
|
||||
path += "A" + Ro + "," + Ro + " 0 0 1 " + (Cx + Ro) + "," + Cy + " ";
|
||||
}
|
||||
path += "A" + Ro + "," + Ro + " 0 0 1 " + Xo + "," + Yo + " ";
|
||||
path += "L" + Xi + "," + Yi + " ";
|
||||
if (value > ((max - min) / 2)) {
|
||||
path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx + Ri) + "," + Cy + " ";
|
||||
}
|
||||
path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx - Ri) + "," + Cy + " ";
|
||||
path += "Z ";
|
||||
|
||||
return { path: path };
|
||||
|
||||
} else {
|
||||
alpha = (1 - (value - min) / (max - min)) * Math.PI;
|
||||
Ro = w / 2 - w / 10;
|
||||
Ri = Ro - w / 6.666666666666667 * gws;
|
||||
|
||||
Cx = w / 2 + dx;
|
||||
Cy = h / 1.25 + dy;
|
||||
|
||||
Xo = w / 2 + dx + Ro * Math.cos(alpha);
|
||||
Yo = h - (h - Cy) + 0 - Ro * Math.sin(alpha);
|
||||
Xi = w / 2 + dx + Ri * Math.cos(alpha);
|
||||
Yi = h - (h - Cy) + 0 - Ri * Math.sin(alpha);
|
||||
|
||||
path += "M" + (Cx - Ri) + "," + Cy + " ";
|
||||
path += "L" + (Cx - Ro) + "," + Cy + " ";
|
||||
path += "A" + Ro + "," + Ro + " 0 0 1 " + Xo + "," + Yo + " ";
|
||||
path += "L" + Xi + "," + Yi + " ";
|
||||
path += "A" + Ri + "," + Ri + " 0 0 0 " + (Cx - Ri) + "," + Cy + " ";
|
||||
path += "Z ";
|
||||
|
||||
return { path: path };
|
||||
}
|
||||
|
||||
// var clear
|
||||
alpha, Ro, Ri, Cx, Cy, Xo, Yo, Xi, Yi, path = null;
|
||||
};
|
||||
|
||||
// gauge
|
||||
this.gauge = this.canvas.path().attr({
|
||||
"stroke": "none",
|
||||
"fill": this.config.gaugeColor,
|
||||
pki: [this.config.max, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut]
|
||||
});
|
||||
this.gauge.id = this.config.id+"-gauge";
|
||||
|
||||
// level
|
||||
this.level = this.canvas.path().attr({
|
||||
"stroke": "none",
|
||||
"fill": getColor(this.config.value, (this.config.value - this.config.min) / (this.config.max - this.config.min), this.config.levelColors, this.config.noGradient, this.config.customSectors),
|
||||
pki: [this.config.min, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut]
|
||||
});
|
||||
if(this.config.donut) {
|
||||
this.level.transform("r" + this.config.donutStartAngle + ", " + (this.params.widgetW/2 + this.params.dx) + ", " + (this.params.widgetH/1.95 + this.params.dy));
|
||||
}
|
||||
this.level.id = this.config.id+"-level";
|
||||
|
||||
// title
|
||||
this.txtTitle = this.canvas.text(this.params.titleX, this.params.titleY, this.config.title);
|
||||
this.txtTitle.attr({
|
||||
"font-size":this.params.titleFontSize,
|
||||
"font-weight":"bold",
|
||||
"font-family":"Arial",
|
||||
"fill":this.config.titleFontColor,
|
||||
"fill-opacity":"1"
|
||||
});
|
||||
setDy(this.txtTitle, this.params.titleFontSize, this.params.titleY);
|
||||
this.txtTitle.id = this.config.id+"-txttitle";
|
||||
|
||||
// value
|
||||
this.txtValue = this.canvas.text(this.params.valueX, this.params.valueY, 0);
|
||||
this.txtValue.attr({
|
||||
"font-size":this.params.valueFontSize,
|
||||
"font-weight":"bold",
|
||||
"font-family":"Arial",
|
||||
"fill":this.config.valueFontColor,
|
||||
"fill-opacity":"0"
|
||||
});
|
||||
setDy(this.txtValue, this.params.valueFontSize, this.params.valueY);
|
||||
this.txtValue.id = this.config.id+"-txtvalue";
|
||||
|
||||
// label
|
||||
this.txtLabel = this.canvas.text(this.params.labelX, this.params.labelY, this.config.label);
|
||||
this.txtLabel.attr({
|
||||
"font-size":this.params.labelFontSize,
|
||||
"font-weight":"normal",
|
||||
"font-family":"Arial",
|
||||
"fill":this.config.labelFontColor,
|
||||
"fill-opacity":"0"
|
||||
});
|
||||
setDy(this.txtLabel, this.params.labelFontSize, this.params.labelY);
|
||||
this.txtLabel.id = this.config.id+"-txtlabel";
|
||||
|
||||
// min
|
||||
this.txtMinimum = this.config.min;
|
||||
if( this.config.humanFriendly ) this.txtMinimum = humanFriendlyNumber( this.config.min, this.config.humanFriendlyDecimal );
|
||||
this.txtMin = this.canvas.text(this.params.minX, this.params.minY, this.txtMinimum);
|
||||
this.txtMin.attr({
|
||||
"font-size":this.params.minFontSize,
|
||||
"font-weight":"normal",
|
||||
"font-family":"Arial",
|
||||
"fill":this.config.labelFontColor,
|
||||
"fill-opacity": (this.config.hideMinMax || this.config.donut)? "0" : "1"
|
||||
});
|
||||
setDy(this.txtMin, this.params.minFontSize, this.params.minY);
|
||||
this.txtMin.id = this.config.id+"-txtmin";
|
||||
|
||||
// max
|
||||
this.txtMaximum = this.config.max;
|
||||
if( this.config.humanFriendly ) this.txtMaximum = humanFriendlyNumber( this.config.max, this.config.humanFriendlyDecimal );
|
||||
this.txtMax = this.canvas.text(this.params.maxX, this.params.maxY, this.txtMaximum);
|
||||
this.txtMax.attr({
|
||||
"font-size":this.params.maxFontSize,
|
||||
"font-weight":"normal",
|
||||
"font-family":"Arial",
|
||||
"fill":this.config.labelFontColor,
|
||||
"fill-opacity": (this.config.hideMinMax || this.config.donut)? "0" : "1"
|
||||
});
|
||||
setDy(this.txtMax, this.params.maxFontSize, this.params.maxY);
|
||||
this.txtMax.id = this.config.id+"-txtmax";
|
||||
|
||||
var defs = this.canvas.canvas.childNodes[1];
|
||||
var svg = "http://www.w3.org/2000/svg";
|
||||
|
||||
if (ie < 9) {
|
||||
onCreateElementNsReady(function() {
|
||||
this.generateShadow(svg, defs);
|
||||
});
|
||||
} else {
|
||||
this.generateShadow(svg, defs);
|
||||
}
|
||||
|
||||
// var clear
|
||||
defs, svg = null;
|
||||
|
||||
// execute on each animation frame
|
||||
function onAnimate() {
|
||||
if (obj.config.counter) {
|
||||
var currentValue = obj.level.attr("pki");
|
||||
|
||||
if(obj.config.textRenderer) {
|
||||
// this.originalValue = this.config.textRenderer(this.originalValue);
|
||||
obj.txtValue.attr("text", obj.config.textRenderer(Math.floor(currentValue[0])));
|
||||
} else if(obj.config.humanFriendly) {
|
||||
// this.originalValue = humanFriendlyNumber( this.originalValue, this.config.humanFriendlyDecimal ) + this.config.symbol;
|
||||
obj.txtValue.attr("text", humanFriendlyNumber( Math.floor(currentValue[0]), obj.config.humanFriendlyDecimal ) + obj.config.symbol);
|
||||
} else {
|
||||
// this.originalValue += this.config.symbol;
|
||||
obj.txtValue.attr("text", (currentValue[0] * 1).toFixed(obj.config.decimals) + obj.config.symbol);
|
||||
}
|
||||
|
||||
setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY);
|
||||
currentValue = null;
|
||||
}
|
||||
}
|
||||
|
||||
if(!obj.config.counter) {
|
||||
if(obj.config.textRenderer) {
|
||||
obj.originalValue = obj.config.textRenderer(obj.originalValue);
|
||||
} else if(obj.config.humanFriendly) {
|
||||
obj.originalValue = humanFriendlyNumber( obj.originalValue, obj.config.humanFriendlyDecimal ) + obj.config.symbol;
|
||||
} else {
|
||||
obj.originalValue = (obj.originalValue * 1).toFixed(obj.config.decimals) + obj.config.symbol;
|
||||
}
|
||||
|
||||
obj.txtValue.attr("text", obj.originalValue);
|
||||
setDy(obj.txtValue, obj.params.valueFontSize, obj.params.valueY);
|
||||
}
|
||||
|
||||
//event fired on each animation frame
|
||||
eve.on("raphael.anim.frame.*", onAnimate);
|
||||
|
||||
// animate gauge level
|
||||
this.level.animate({pki: [this.config.value, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut]}, this.config.startAnimationTime, this.config.startAnimationType);
|
||||
|
||||
// animate value
|
||||
this.txtValue.animate({"fill-opacity":"1"}, this.config.startAnimationTime, this.config.startAnimationType);
|
||||
|
||||
// animate label
|
||||
this.txtLabel.animate({"fill-opacity":"1"}, this.config.startAnimationTime, this.config.startAnimationType);
|
||||
};
|
||||
|
||||
/** Refresh gauge level */
|
||||
JustGage.prototype.refresh = function(val, max) {
|
||||
|
||||
var originalVal, displayVal, color, max = max || null;
|
||||
|
||||
// set new max
|
||||
if(max !== null) {
|
||||
this.config.max = max;
|
||||
|
||||
this.txtMaximum = this.config.max;
|
||||
if( this.config.humanFriendly ) this.txtMaximum = humanFriendlyNumber( this.config.max, this.config.humanFriendlyDecimal );
|
||||
this.txtMax.attr({"text" : this.config.max});
|
||||
setDy(this.txtMax, this.params.maxFontSize, this.params.maxY);
|
||||
}
|
||||
|
||||
// overflow values
|
||||
originalVal = val;
|
||||
displayVal = val;
|
||||
if ((val * 1) > (this.config.max * 1)) {val = (this.config.max * 1);}
|
||||
if ((val * 1) < (this.config.min * 1)) {val = (this.config.min * 1);}
|
||||
|
||||
color = getColor(val, (val - this.config.min) / (this.config.max - this.config.min), this.config.levelColors, this.config.noGradient, this.config.customSectors);
|
||||
|
||||
if(this.config.textRenderer) {
|
||||
displayVal = this.config.textRenderer(displayVal);
|
||||
} else if( this.config.humanFriendly ) {
|
||||
displayVal = humanFriendlyNumber( displayVal, this.config.humanFriendlyDecimal ) + this.config.symbol;
|
||||
} else {
|
||||
displayVal = (displayVal * 1).toFixed(this.config.decimals) + this.config.symbol;
|
||||
}
|
||||
|
||||
if(!this.config.counter) {
|
||||
this.canvas.getById(this.config.id+"-txtvalue").attr({"text":displayVal});
|
||||
setDy(this.canvas.getById(this.config.id+"-txtvalue"), this.params.valueFontSize, this.params.valueY);
|
||||
}
|
||||
|
||||
this.canvas.getById(this.config.id+"-level").animate({pki: [val, this.config.min, this.config.max, this.params.widgetW, this.params.widgetH, this.params.dx, this.params.dy, this.config.gaugeWidthScale, this.config.donut], "fill":color}, this.config.refreshAnimationTime, this.config.refreshAnimationType);
|
||||
this.config.value = val * 1;
|
||||
|
||||
// var clear
|
||||
originalVal, displayVal, color, max = null;
|
||||
};
|
||||
|
||||
/** Generate shadow */
|
||||
JustGage.prototype.generateShadow = function(svg, defs) {
|
||||
|
||||
var gaussFilter, feOffset, feGaussianBlur, feComposite1, feFlood, feComposite2, feComposite3;
|
||||
|
||||
// FILTER
|
||||
gaussFilter=document.createElementNS(svg,"filter");
|
||||
gaussFilter.setAttribute("id", this.config.id + "-inner-shadow");
|
||||
defs.appendChild(gaussFilter);
|
||||
|
||||
// offset
|
||||
feOffset = document.createElementNS(svg,"feOffset");
|
||||
feOffset.setAttribute("dx", 0);
|
||||
feOffset.setAttribute("dy", this.config.shadowVerticalOffset);
|
||||
gaussFilter.appendChild(feOffset);
|
||||
|
||||
// blur
|
||||
feGaussianBlur = document.createElementNS(svg,"feGaussianBlur");
|
||||
feGaussianBlur.setAttribute("result","offset-blur");
|
||||
feGaussianBlur.setAttribute("stdDeviation", this.config.shadowSize);
|
||||
gaussFilter.appendChild(feGaussianBlur);
|
||||
|
||||
// composite 1
|
||||
feComposite1 = document.createElementNS(svg,"feComposite");
|
||||
feComposite1.setAttribute("operator","out");
|
||||
feComposite1.setAttribute("in", "SourceGraphic");
|
||||
feComposite1.setAttribute("in2","offset-blur");
|
||||
feComposite1.setAttribute("result","inverse");
|
||||
gaussFilter.appendChild(feComposite1);
|
||||
|
||||
// flood
|
||||
feFlood = document.createElementNS(svg,"feFlood");
|
||||
feFlood.setAttribute("flood-color","black");
|
||||
feFlood.setAttribute("flood-opacity", this.config.shadowOpacity);
|
||||
feFlood.setAttribute("result","color");
|
||||
gaussFilter.appendChild(feFlood);
|
||||
|
||||
// composite 2
|
||||
feComposite2 = document.createElementNS(svg,"feComposite");
|
||||
feComposite2.setAttribute("operator","in");
|
||||
feComposite2.setAttribute("in", "color");
|
||||
feComposite2.setAttribute("in2","inverse");
|
||||
feComposite2.setAttribute("result","shadow");
|
||||
gaussFilter.appendChild(feComposite2);
|
||||
|
||||
// composite 3
|
||||
feComposite3 = document.createElementNS(svg,"feComposite");
|
||||
feComposite3.setAttribute("operator","over");
|
||||
feComposite3.setAttribute("in", "shadow");
|
||||
feComposite3.setAttribute("in2","SourceGraphic");
|
||||
gaussFilter.appendChild(feComposite3);
|
||||
|
||||
// set shadow
|
||||
if (!this.config.hideInnerShadow) {
|
||||
this.canvas.canvas.childNodes[2].setAttribute("filter", "url(#" + this.config.id + "-inner-shadow)");
|
||||
this.canvas.canvas.childNodes[3].setAttribute("filter", "url(#" + this.config.id + "-inner-shadow)");
|
||||
}
|
||||
|
||||
// var clear
|
||||
gaussFilter, feOffset, feGaussianBlur, feComposite1, feFlood, feComposite2, feComposite3 = null;
|
||||
|
||||
};
|
||||
|
||||
/** Get color for value */
|
||||
function getColor(val, pct, col, noGradient, custSec) {
|
||||
|
||||
var no, inc, colors, percentage, rval, gval, bval, lower, upper, range, rangePct, pctLower, pctUpper, color;
|
||||
var noGradient = noGradient || custSec.length > 0;
|
||||
|
||||
if(custSec.length > 0) {
|
||||
for(var i = 0; i < custSec.length; i++) {
|
||||
if(val > custSec[i].lo && val <= custSec[i].hi) {
|
||||
return custSec[i].color;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
no = col.length;
|
||||
if (no === 1) return col[0];
|
||||
inc = (noGradient) ? (1 / no) : (1 / (no - 1));
|
||||
colors = [];
|
||||
for (var i = 0; i < col.length; i++) {
|
||||
percentage = (noGradient) ? (inc * (i + 1)) : (inc * i);
|
||||
rval = parseInt((cutHex(col[i])).substring(0,2),16);
|
||||
gval = parseInt((cutHex(col[i])).substring(2,4),16);
|
||||
bval = parseInt((cutHex(col[i])).substring(4,6),16);
|
||||
colors[i] = { pct: percentage, color: { r: rval, g: gval, b: bval } };
|
||||
}
|
||||
|
||||
if(pct === 0) {
|
||||
return 'rgb(' + [colors[0].color.r, colors[0].color.g, colors[0].color.b].join(',') + ')';
|
||||
}
|
||||
|
||||
for (var j = 0; j < colors.length; j++) {
|
||||
if (pct <= colors[j].pct) {
|
||||
if (noGradient) {
|
||||
return 'rgb(' + [colors[j].color.r, colors[j].color.g, colors[j].color.b].join(',') + ')';
|
||||
} else {
|
||||
lower = colors[j - 1];
|
||||
upper = colors[j];
|
||||
range = upper.pct - lower.pct;
|
||||
rangePct = (pct - lower.pct) / range;
|
||||
pctLower = 1 - rangePct;
|
||||
pctUpper = rangePct;
|
||||
color = {
|
||||
r: Math.floor(lower.color.r * pctLower + upper.color.r * pctUpper),
|
||||
g: Math.floor(lower.color.g * pctLower + upper.color.g * pctUpper),
|
||||
b: Math.floor(lower.color.b * pctLower + upper.color.b * pctUpper)
|
||||
};
|
||||
return 'rgb(' + [color.r, color.g, color.b].join(',') + ')';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Fix Raphael display:none tspan dy attribute bug */
|
||||
function setDy(elem, fontSize, txtYpos) {
|
||||
if ((!ie || ie > 9) && (elem.node.firstChild.attributes.dy)) {
|
||||
elem.node.firstChild.attributes.dy.value = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/** Random integer */
|
||||
function getRandomInt (min, max) {
|
||||
return Math.floor(Math.random() * (max - min + 1)) + min;
|
||||
}
|
||||
|
||||
/** Cut hex */
|
||||
function cutHex(str) {
|
||||
return (str.charAt(0)=="#") ? str.substring(1,7):str;
|
||||
}
|
||||
|
||||
/** Human friendly number suffix - From: http://stackoverflow.com/questions/2692323/code-golf-friendly-number-abbreviator */
|
||||
function humanFriendlyNumber( n, d ) {
|
||||
var p, d2, i, s;
|
||||
|
||||
p = Math.pow;
|
||||
d2 = p(10, d);
|
||||
i = 7;
|
||||
while( i ) {
|
||||
s = p(10,i--*3);
|
||||
if( s <= n ) {
|
||||
n = Math.round(n*d2/s)/d2+"KMGTPE"[i];
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
/** Get style */
|
||||
function getStyle(oElm, strCssRule){
|
||||
var strValue = "";
|
||||
if(document.defaultView && document.defaultView.getComputedStyle){
|
||||
strValue = document.defaultView.getComputedStyle(oElm).getPropertyValue(strCssRule);
|
||||
}
|
||||
else if(oElm.currentStyle){
|
||||
strCssRule = strCssRule.replace(/\-(\w)/g, function (strMatch, p1){
|
||||
return p1.toUpperCase();
|
||||
});
|
||||
strValue = oElm.currentStyle[strCssRule];
|
||||
}
|
||||
return strValue;
|
||||
}
|
||||
|
||||
/** Create Element NS Ready */
|
||||
function onCreateElementNsReady(func) {
|
||||
if (document.createElementNS !== undefined) {
|
||||
func();
|
||||
} else {
|
||||
setTimeout(function() { onCreateElementNsReady(func); }, 100);
|
||||
}
|
||||
}
|
||||
|
||||
/** Get IE version */
|
||||
// ----------------------------------------------------------
|
||||
// A short snippet for detecting versions of IE in JavaScript
|
||||
// without resorting to user-agent sniffing
|
||||
// ----------------------------------------------------------
|
||||
// If you're not in IE (or IE version is less than 5) then:
|
||||
// ie === undefined
|
||||
// If you're in IE (>=5) then you can determine which version:
|
||||
// ie === 7; // IE7
|
||||
// Thus, to detect IE:
|
||||
// if (ie) {}
|
||||
// And to detect the version:
|
||||
// ie === 6 // IE6
|
||||
// ie > 7 // IE8, IE9 ...
|
||||
// ie < 9 // Anything less than IE9
|
||||
// ----------------------------------------------------------
|
||||
// UPDATE: Now using Live NodeList idea from @jdalton
|
||||
var ie = (function(){
|
||||
|
||||
var undef,
|
||||
v = 3,
|
||||
div = document.createElement('div'),
|
||||
all = div.getElementsByTagName('i');
|
||||
|
||||
while (
|
||||
div.innerHTML = '<!--[if gt IE ' + (++v) + ']><i></i><![endif]-->',
|
||||
all[0]
|
||||
);
|
||||
return v > 4 ? v : undef;
|
||||
}());
|
|
@ -1,108 +0,0 @@
|
|||
openerp.sale_crm = function(openerp) {
|
||||
var _t = openerp.web._t;
|
||||
|
||||
openerp.sale_crm.GaugeWidget = openerp.web_kanban.AbstractField.extend({
|
||||
className: "oe_gage",
|
||||
start: function() {
|
||||
var self = this;
|
||||
|
||||
var parent = this.getParent();
|
||||
var max = this.options.max_field ? parent.record[this.options.max_field].raw_value : 100;
|
||||
var label = this.options.label_field ? parent.record[this.options.label_field].raw_value : "";
|
||||
var title = this.$node.html();
|
||||
var val = this.field.value;
|
||||
var value = _.isArray(val) && val.length ? val[val.length-1]['value'] : val;
|
||||
var unique_id = _.uniqueId("JustGage");
|
||||
|
||||
this.$el.empty()
|
||||
.attr('style', this.$node.attr('style') + ';position:relative; display:inline-block;')
|
||||
.attr('id', unique_id);
|
||||
this.gage = new JustGage({
|
||||
id: unique_id,
|
||||
node: this.$el[0],
|
||||
title: title,
|
||||
value: value,
|
||||
min: 0,
|
||||
max: max,
|
||||
relativeGaugeSize: true,
|
||||
humanFriendly: true,
|
||||
titleFontColor: '#333333',
|
||||
valueFontColor: '#333333',
|
||||
labelFontColor: '#000',
|
||||
label: label,
|
||||
levelColors: [
|
||||
"#ff0000",
|
||||
"#f9c802",
|
||||
"#a9d70b"
|
||||
],
|
||||
});
|
||||
|
||||
var flag_open = false;
|
||||
if (self.options.action_change) {
|
||||
var $svg = self.$el.find('svg');
|
||||
var css = {
|
||||
'text-align': 'center',
|
||||
'position': 'absolute',
|
||||
'width': self.$el.outerWidth() + 'px',
|
||||
'top': (self.$el.outerHeight()/2-5) + 'px'
|
||||
};
|
||||
|
||||
self.$el.click(function (event) {
|
||||
event.stopPropagation();
|
||||
flag_open = false;
|
||||
if (!parent.view.is_action_enabled('edit')) {
|
||||
return;
|
||||
}
|
||||
if (!self.$el.find(".oe_justgage_edit").size()) {
|
||||
$div = $('<div class="oe_justgage_edit" style="z-index:1"/>');
|
||||
$div.css(css);
|
||||
$input = $('<input/>').val(value);
|
||||
$input.css({
|
||||
'text-align': 'center',
|
||||
'margin': 'auto',
|
||||
'width': ($svg.outerWidth()-40) + 'px'
|
||||
});
|
||||
$div.append($input);
|
||||
self.$el.prepend($div)
|
||||
$input.focus()
|
||||
.keydown(function (event) {
|
||||
event.stopPropagation();
|
||||
if (event.keyCode == 13 || event.keyCode == 9) {
|
||||
if ($input.val() != value) {
|
||||
parent.view.dataset.call(self.options.action_change, [parent.id, $input.val()]).then(function () {
|
||||
parent.do_reload();
|
||||
});
|
||||
} else {
|
||||
$div.remove();
|
||||
}
|
||||
}
|
||||
})
|
||||
.click(function (event) {
|
||||
event.stopPropagation();
|
||||
flag_open = false;
|
||||
})
|
||||
.blur(function (event) {
|
||||
if(!flag_open) {
|
||||
self.$el.find(".oe_justgage_edit").remove();
|
||||
} else {
|
||||
flag_open = false;
|
||||
setTimeout(function () {$input.focus();}, 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
}).mousedown(function () {
|
||||
flag_open = true;
|
||||
});
|
||||
|
||||
if (!+value) {
|
||||
$svg.fadeTo(0, 0.3);
|
||||
$div = $('<div/>').text(_t("Click to change value"));
|
||||
$div.css(css);
|
||||
self.$el.append($div);
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
openerp.web_kanban.fields_registry.add("gage", "openerp.sale_crm.GaugeWidget");
|
||||
|
||||
};
|
Loading…
Reference in New Issue