wpml-tm-editor-footer-view.js
4.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/*global jQuery, ajaxurl, Backbone, WpmlTmEditorModel, window, tmEditorStrings, _ */
var WPML_TM = WPML_TM || {};
(function () {
"use strict";
WPML_TM.editorFooterView = Backbone.View.extend({
tagName: 'footer',
className: 'wpml-translation-action-buttons',
events: {
'click .js-save': 'save',
'click .js-resign': 'resign',
'click .js-dialog-cancel': 'cancel',
'click .js-save-and-close': 'save_and_close',
'change .js-toggle-translated': 'toggleTranslated'
},
initialize: function (options) {
var self = this;
self.mainView = options.mainView;
self.listenTo(self.model, 'translationUpdated', self.setDirty);
},
save: function () {
var self = this;
self.doSave();
},
editIndependently: function () {
WpmlTmEditorModel.is_duplicate = false;
},
doSave: function () {
var self = this;
var saveMessage = jQuery('.js-saving-message');
saveMessage.show();
self.disableButtons(true);
self.listenToOnce(self.model, 'saveJobSuccess', function () {
saveMessage.hide();
self.disableButtons(false);
});
self.model.save(jQuery('#icl_tm_editor').serialize());
self.setDirty(false);
return self;
},
resign: function () {
if (window.confirm(tmEditorStrings.resign_translation)) {
window.location.href = WPML_core.sanitize( tmEditorStrings.resign_url );
}
},
cancel: function () {
this.redirect_to_return_url('wpml_tm_cancel=1');
},
save_and_close: function () {
var self = this;
self.listenToOnce(self.model, 'saveJobSuccess', function () {
self.setDirty(false);
this.redirect_to_return_url('wpml_tm_saved=1');
});
self.save();
},
redirect_to_return_url: function (param_string) {
var url = WpmlTmEditorModel.return_url;
if (url.indexOf('?') < 0) {
url += '?' + param_string;
} else {
url += '&' + param_string;
}
window.location = WPML_core.sanitize( url );
},
render: function () {
var self = this;
self.$el.html(WPML_TM['templates/translation-editor/footer.html'](tmEditorStrings));
self.progressBar = self.$el.find('.js-progress-bar');
self.translationComplete = self.$el.find(':checkbox[name=complete]');
self.showProgressBar();
self.maybeShowTranslationComplete();
self.maybeHideHideCompletedSwitcher();
window.onbeforeunload = function (e) {
if (self.isDirty()) {
return tmEditorStrings.confirmNavigate;
}
};
_.defer(_.bind(self.maybeShowDuplicateDialog, self));
},
maybeShowDuplicateDialog: function () {
var self = this;
if (WpmlTmEditorModel.is_duplicate) {
self.dialog = new WPML_TM.editorEditIndependentlyDialog(self);
}
},
showProgressBar: function () {
var self = this;
self.progressBar.css('display', WpmlTmEditorModel.requires_translation_complete_for_each_field ? 'inline-block' : 'none');
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
self.progressBar.progressbar({});
var value = parseInt(self.model.progressPercentage(), 10);
self.progressBar.find('.progress-bar-text').html(value + '% Complete');
self.progressBar.find('.ui-progressbar-value').attr('data-progressbar-text', value + '% Complete');
self.progressBar.progressbar({value: value});
self.progressBar.find('.ui-progressbar-value').height(self.progressBar.find('.progress-bar-text').height());
return self;
},
setCompleteCheckBox: function () {
var self = this;
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
self.translationComplete.prop('checked', self.model.progressPercentage() === 100);
}
return self;
},
maybeShowTranslationComplete: function () {
var self = this;
if (WpmlTmEditorModel.requires_translation_complete_for_each_field) {
self.translationComplete.parent().hide();
} else {
self.translationComplete.prop('checked', WpmlTmEditorModel.translation_is_complete);
}
},
maybeHideHideCompletedSwitcher: function () {
var self = this;
if (!WpmlTmEditorModel.display_hide_completed_switcher) {
self.$el.find('#wpml_tm_toggle_translated').parent().hide();
}
},
progressBar: function () {
return this.$el.find('.js-progress-bar');
},
setDirty: function (value) {
this.model.set('is_dirty', value);
},
isDirty: function () {
return this.model.get('is_dirty');
},
disableButtons: function (state) {
this.$el.find('.js-save, .js-resign, .js-dialog-cancel, .js-save-and-close').prop('disabled', state);
},
disableSaveButtons: function (state) {
this.$el.find('.js-save, .js-save-and-close').prop('disabled', state);
},
hideResignButton: function (state) {
if (state) {
this.$el.find('.js-resign').hide();
} else {
this.$el.find('.js-resign').show();
}
},
toggleTranslated: function() {
var toggle = this.$el.find('.js-toggle-translated');
this.mainView.hideTranslated(toggle.is(':checked'));
}
});
}());