Browse Source

Removed redudant imports. Using timega jQuery library delivered with odoo core.

pull/1/head
s0x90 9 years ago
parent
commit
da223440ce
  1. 129
      static/lib/js/livestamp.js
  2. 3111
      static/lib/js/moment.js
  3. 10
      static/src/js/main.js
  4. 2
      views.xml

129
static/lib/js/livestamp.js

@ -1,129 +0,0 @@
// Livestamp.js / v1.1.2 / (c) 2012 Matt Bradley / MIT License
(function($, moment) {
var updateInterval = 1e3,
paused = false,
$livestamps = $([]),
init = function() {
livestampGlobal.resume();
},
prep = function($el, timestamp) {
var oldData = $el.data('livestampdata');
if (typeof timestamp == 'number')
timestamp *= 1e3;
$el.removeAttr('data-livestamp')
.removeData('livestamp');
timestamp = moment(timestamp);
if (moment.isMoment(timestamp) && !isNaN(+timestamp)) {
var newData = $.extend({ }, { 'original': $el.contents() }, oldData);
newData.moment = moment(timestamp);
$el.data('livestampdata', newData).empty();
$livestamps.push($el[0]);
}
},
run = function() {
if (paused) return;
livestampGlobal.update();
setTimeout(run, updateInterval);
},
livestampGlobal = {
update: function() {
$('[data-livestamp]').each(function() {
var $this = $(this);
prep($this, $this.data('livestamp'));
});
var toRemove = [];
$livestamps.each(function() {
var $this = $(this),
data = $this.data('livestampdata');
if (data === undefined)
toRemove.push(this);
else if (moment.isMoment(data.moment)) {
var from = $this.html(),
to = data.moment.fromNow();
if (from != to) {
var e = $.Event('change.livestamp');
$this.trigger(e, [from, to]);
if (!e.isDefaultPrevented())
$this.html(to);
}
}
});
$livestamps = $livestamps.not(toRemove);
},
pause: function() {
paused = true;
},
resume: function() {
paused = false;
run();
},
interval: function(interval) {
if (interval === undefined)
return updateInterval;
updateInterval = interval;
}
},
livestampLocal = {
add: function($el, timestamp) {
if (typeof timestamp == 'number')
timestamp *= 1e3;
timestamp = moment(timestamp);
if (moment.isMoment(timestamp) && !isNaN(+timestamp)) {
$el.each(function() {
prep($(this), timestamp);
});
livestampGlobal.update();
}
return $el;
},
destroy: function($el) {
$livestamps = $livestamps.not($el);
$el.each(function() {
var $this = $(this),
data = $this.data('livestampdata');
if (data === undefined)
return $el;
$this
.html(data.original ? data.original : '')
.removeData('livestampdata');
});
return $el;
},
isLivestamp: function($el) {
return $el.data('livestampdata') !== undefined;
}
};
$.livestamp = livestampGlobal;
$(init);
$.fn.livestamp = function(method, options) {
if (!livestampLocal[method]) {
options = method;
method = 'add';
}
return livestampLocal[method](this, options);
};
})(jQuery, moment);

3111
static/lib/js/moment.js
File diff suppressed because it is too large
View File

10
static/src/js/main.js

@ -31,18 +31,16 @@ openerp.mail_check_immediately = function(instance, local) {
var _this = this; var _this = this;
this.imm_model.call('run_fetchmail_manually', {context: new instance.web.CompoundContext()}).then(function(){ this.imm_model.call('run_fetchmail_manually', {context: new instance.web.CompoundContext()}).then(function(){
_this.get_last_fetched_time('updateFromDOM')
_this.get_last_fetched_time()
}) })
}, },
get_last_fetched_time: function(action){
get_last_fetched_time: function(){
var _this = this; var _this = this;
this.imm_model.call('get_last_update_time', {context: new instance.web.CompoundContext()}).then(function(res){ this.imm_model.call('get_last_update_time', {context: new instance.web.CompoundContext()}).then(function(res){
_this.$el.find('span.oe_view_manager_fetch_mail_imm_field')
.livestamp(new Date(res))
// using jQuery timeago library
_this.$el.find('span.oe_view_manager_fetch_mail_imm_field').html($.timeago(res));
}) })
}, },
destroy: function(){ destroy: function(){

2
views.xml

@ -2,8 +2,6 @@
<data> <data>
<template id="assets_backend_inherited_check_mail" name="Check mail immediately bar" inherit_id="web.assets_backend"> <template id="assets_backend_inherited_check_mail" name="Check mail immediately bar" inherit_id="web.assets_backend">
<xpath expr="." position="inside"> <xpath expr="." position="inside">
<script type="text/javascript" src="/mail_check_immediately/static/lib/js/moment.js"></script>
<script type="text/javascript" src="/mail_check_immediately/static/lib/js/livestamp.js"></script>
<script type="text/javascript" src="/mail_check_immediately/static/src/js/main.js"></script> <script type="text/javascript" src="/mail_check_immediately/static/src/js/main.js"></script>
</xpath> </xpath>
</template> </template>

Loading…
Cancel
Save