fix autoclose to work with jquery 1.9 and moment js
This commit is contained in:
parent
e6e81efe85
commit
28853177fd
|
@ -33,7 +33,7 @@ Discourse.EditTopicAutoCloseController = Discourse.ObjectController.extend(Disco
|
||||||
Discourse.ajax({
|
Discourse.ajax({
|
||||||
url: '/t/' + this.get('id') + '/autoclose',
|
url: '/t/' + this.get('id') + '/autoclose',
|
||||||
type: 'PUT',
|
type: 'PUT',
|
||||||
dataType: 'json',
|
dataType: 'html', // no custom errors, jquery 1.9 enforces json
|
||||||
data: { auto_close_days: days > 0 ? days : null }
|
data: { auto_close_days: days > 0 ? days : null }
|
||||||
}).then(function(){
|
}).then(function(){
|
||||||
editTopicAutoCloseController.set('auto_close_at', moment().add('days', days).format());
|
editTopicAutoCloseController.set('auto_close_at', moment().add('days', days).format());
|
||||||
|
|
|
@ -18,40 +18,43 @@ Discourse.TopicClosingView = Discourse.View.extend({
|
||||||
render: function(buffer) {
|
render: function(buffer) {
|
||||||
if (!this.present('topic.auto_close_at')) return;
|
if (!this.present('topic.auto_close_at')) return;
|
||||||
|
|
||||||
var autoCloseAt = new Date(this.get('topic.auto_close_at'));
|
var autoCloseAt = moment(this.get('topic.auto_close_at'));
|
||||||
|
|
||||||
if (autoCloseAt.isPast()) return;
|
if (autoCloseAt < new Date()) return;
|
||||||
|
|
||||||
var timeLeftString, reRenderDelay, minutesLeft = autoCloseAt.minutesSince();
|
var duration = moment.duration(autoCloseAt - moment());
|
||||||
|
|
||||||
if (minutesLeft > 1440) {
|
var timeLeftString, rerenderDelay, minutesLeft = duration.asMinutes();
|
||||||
timeLeftString = Em.String.i18n('in_n_days', {count: autoCloseAt.daysSince()});
|
|
||||||
|
if (minutesLeft > 1410) {
|
||||||
|
timeLeftString = Em.String.i18n('in_n_days', {count: Math.round(duration.asDays())});
|
||||||
if( minutesLeft > 2160 ) {
|
if( minutesLeft > 2160 ) {
|
||||||
reRenderDelay = 12 * 60 * 60000;
|
rerenderDelay = 12 * 60 * 60000;
|
||||||
} else {
|
} else {
|
||||||
reRenderDelay = 60 * 60000;
|
rerenderDelay = 60 * 60000;
|
||||||
}
|
}
|
||||||
} else if (minutesLeft > 90) {
|
} else if (minutesLeft > 90) {
|
||||||
timeLeftString = Em.String.i18n('in_n_hours', {count: autoCloseAt.hoursSince()});
|
timeLeftString = Em.String.i18n('in_n_hours', {count: Math.round(duration.asHours())});
|
||||||
reRenderDelay = 30 * 60000;
|
rerenderDelay = 30 * 60000;
|
||||||
} else if (minutesLeft > 2) {
|
} else if (minutesLeft > 2) {
|
||||||
timeLeftString = Em.String.i18n('in_n_minutes', {count: autoCloseAt.minutesSince()});
|
timeLeftString = Em.String.i18n('in_n_minutes', {count: Math.round(duration.asMinutes())});
|
||||||
reRenderDelay = 60000;
|
rerenderDelay = 60000;
|
||||||
} else {
|
} else {
|
||||||
timeLeftString = Em.String.i18n('in_n_seconds', {count: autoCloseAt.secondsSince()});
|
timeLeftString = Em.String.i18n('in_n_seconds', {count: Math.round(duration.asSeconds())});
|
||||||
reRenderDelay = 1000;
|
rerenderDelay = 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
buffer.push('<h3><i class="icon icon-time"></i> ');
|
buffer.push('<h3><i class="icon icon-time"></i> ');
|
||||||
buffer.push( Em.String.i18n('topic.auto_close_notice', {timeLeft: timeLeftString}) );
|
buffer.push( Em.String.i18n('topic.auto_close_notice', {timeLeft: timeLeftString}) );
|
||||||
buffer.push('</h3>');
|
buffer.push('</h3>');
|
||||||
|
|
||||||
this.delayedRerender = this.rerender.bind(this).delay(reRenderDelay);
|
// TODO Sam: concerned this can cause a heavy rerender loop
|
||||||
|
this.delayedRerender = Em.run.later(this, this.rerender, rerenderDelay);
|
||||||
},
|
},
|
||||||
|
|
||||||
willDestroyElement: function() {
|
willDestroyElement: function() {
|
||||||
if( this.delayedRerender ) {
|
if( this.delayedRerender ) {
|
||||||
this.delayedRerender.cancel();
|
Em.run.cancel(this.delayedRerender)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue