if (Common === undefined)
var Common = {};
define([
'common/main/lib/component/BaseView'
], function () {
'use strict';
Common.UI.SynchronizeTip = Common.UI.BaseView.extend(_.extend((function() {
var tipEl;
return {
options : {
target : $(document.body),
text : '',
placement: 'right'
},
template: _.template([
'
',
'
',
'
',
'
',
'
<%= scope.text %>
',
'
',
'
',
'
',
'
',
'
'
].join('')),
initialize : function(options) {
this.textSynchronize += Common.Utils.String.platformKey('Ctrl+S');
Common.UI.BaseView.prototype.initialize.call(this, options);
this.target = this.options.target;
this.text = !_.isEmpty(this.options.text) ? this.options.text : this.textSynchronize;
this.placement = this.options.placement;
},
render: function() {
tipEl = $(this.template({ scope: this }));
tipEl.find('.close').on('click', _.bind(function() { this.trigger('closeclick');}, this));
tipEl.find('.show-link label').on('click', _.bind(function() { this.trigger('dontshowclick');}, this));
$(document.body).append(tipEl);
this.applyPlacement();
return this;
},
show: function(){
if (tipEl) {
this.applyPlacement();
tipEl.show()
} else
this.render();
},
hide: function() {
if (tipEl) tipEl.hide();
},
applyPlacement: function () {
var showxy = this.target.offset();
(this.placement == 'top') ? tipEl.css({bottom : $(document).height() - showxy.top + 'px', right: $(document).width() - showxy.left - this.target.width()/2 + 'px'})
: tipEl.css({top : showxy.top + this.target.height()/2 + 'px', left: showxy.left + this.target.width() + 'px'});
},
textDontShow : 'Don\'t show this message again',
textSynchronize : 'The document has been changed by another user.
Please click to save your changes and reload the updates.'
}
})(), Common.UI.SynchronizeTip || {}));
});