exvo_globalize 0.5.4 → 0.5.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -30,6 +30,15 @@ This gem also integrates your application with [Globalize](http://store.exvo.com
30
30
  Rails 3.0+ (works both with Rails 3.0.* and Rails 3.1.*)
31
31
 
32
32
 
33
+ ## Updating from versions below v0.5.4
34
+
35
+ Please execute the install command again to add new migrations
36
+
37
+ or run
38
+
39
+ ```bash
40
+ $ rake globalize:update
41
+ ```
33
42
 
34
43
  ## Installation
35
44
 
@@ -231,7 +240,16 @@ translations = @globalize_app.fetch_translations
231
240
  I18n.backend.store_nested_translations(translations)
232
241
  ```
233
242
 
243
+ ## Feedback system
234
244
 
245
+ It's a voting system which allows users to send feedback for phrases currently loaded at your application.
246
+
247
+ The following code will create a link to the the feedback interface.
248
+
249
+ ```ruby
250
+ link_to_globalize_feedback(TEXT_FOR_LINK, LOCALE)
251
+
252
+ ```
235
253
 
236
254
  ## Running the specs
237
255
 
@@ -0,0 +1,118 @@
1
+ $(document).ready(function() {
2
+ if ($("#viewport").length == 0) {
3
+ $(".viewport:first").attr('id', 'viewport');
4
+ }
5
+
6
+ $.layout = new $.ui.layout(".layout");
7
+ $.layout._init();
8
+ $.layout.refresh = function(){
9
+ this._resize();
10
+ this._equalize_cells();
11
+
12
+ if( typeof after_resize == 'function' ) {
13
+ after_resize( cnt );
14
+ }
15
+ }
16
+
17
+ $('select').parents('.selector').each(function (){ $(this).addClass($('select', this).attr('class'))} );
18
+ $('button:not(.disabled)').removeAttr("disabled");
19
+ $('button.disabled').attr("disabled","disabled");
20
+
21
+ var cnt = $('body');
22
+ // init uniform
23
+ // if ($.isFunction($.fn.uniform)){
24
+ $("select, input:checkbox, input:radio, input:file", cnt).uniform()
25
+ $('select').parents('.selector').each(function (){ $(this).addClass($('select', this).attr('class'))} );
26
+ // }
27
+
28
+ // init tables
29
+ $( 'table.fill:has(tbody):visible', cnt ).each( function(){
30
+ var $table = $( this )
31
+ var $tbody = $( 'tbody', $table )
32
+ var $row = $('<tr><td>&nbsp;</td></tr>')
33
+ if ( $('tr:has(td):last', $table).length > 0 ){
34
+ $row = $('tr:has(td):last', $table).clone()
35
+ $( 'td', $row ).html('&nbsp;')
36
+ var remove_attrs = ['id', 'onclick', 'onchange', 'class']
37
+ var attrs = $.map($row.get(0).attributes, function (a) { return a.nodeName; });
38
+ for (var i=0; i<attrs.length; i++){
39
+ if ( attrs[i].indexOf('data') == 0 || $.inArray(attrs[i], remove_attrs) != -1 )
40
+ $row.removeAttr( attrs[i] )
41
+ }
42
+ } else {
43
+ var colspan = 0
44
+ $('tr:first', $table).children().filter(':visible').each( function(){ colspan = colspan + parseInt($(this).attr('colSpan')) })
45
+ if (colspan != 0)
46
+ $('td:first', $row).attr('colSpan', colspan)
47
+ }
48
+
49
+ var limit = 50
50
+ var $parent = $table.parents('div:first')
51
+ while ( ( $parent.outerHeight() * 2 /* *2 is temp fix */ - $table.outerHeight() ) >= -1 && limit > 0 ){
52
+ $tbody.append( $row.clone() )
53
+ limit = limit - 1
54
+ }
55
+ });
56
+
57
+ var page = 1;
58
+ var loading = false;
59
+
60
+ var nearBottomOfPage = function() {
61
+ return $(".content").scrollTop() > $(".feedback").height() - 600;
62
+ }
63
+
64
+ $(".content").scroll(function(){
65
+ if (nearBottomOfPage() && !loading) {
66
+ page++;
67
+ loading = true;
68
+ locale = $("#locale").val();
69
+ $.get('/globalize/translations/feedback?locale=' + locale + '&page=' + page, function(data) {
70
+ $(".feedback").append(data);
71
+ });
72
+ }
73
+ });
74
+
75
+ $(".feedback").delegate(".send_feedback", "click", function() {
76
+ var self = $(this);
77
+ var current_globalize_translation_id = self.attr("globalize-translation-id");
78
+
79
+ if (cookie('phrase_suggestion_for_' + current_globalize_translation_id) != null) {
80
+ alert('Your feedback is currently under review. Thanks.');
81
+ return;
82
+ } else {
83
+ if (current_globalize_translation_id == null || current_globalize_translation_id == '') {
84
+ alert('No phrase was selected.');
85
+ return;
86
+ }
87
+
88
+ var url = "/globalize/translations/send_feedback/" + current_globalize_translation_id;
89
+ var body = self.parents("tr").find(".suggestion").val();
90
+ var current_selected_suggestion = self.parents("tr").find("select.suggestion_options").val();
91
+ var data = null;
92
+
93
+ if (body != null && body != '') {
94
+ data = { body: body };
95
+ } else if (current_selected_suggestion != null && current_selected_suggestion != '') {
96
+ data = { globalize_translation_suggestion_id: current_selected_suggestion }
97
+ }
98
+
99
+ if (data == null) {
100
+ alert('Please, select a suggestion or send a new one.');
101
+ return;
102
+ }
103
+
104
+ $.ajax({
105
+ type: 'POST',
106
+ url: url,
107
+ data: data,
108
+ success: function(data, textStatus, xmlHttpRequest){
109
+ cookie('phrase_suggestion_for_' + current_globalize_translation_id, current_globalize_translation_id);
110
+ self.parents("td").html("Sent");
111
+ },
112
+ error: function(xht){
113
+ alert($.parseJSON(xht.response).errors.join(", "));
114
+ }
115
+ });
116
+ }
117
+ });
118
+ });
@@ -1,6 +1,6 @@
1
1
  //
2
2
  // exvo_globalize_i18n.js
3
- // Version: 0.5.4
3
+ // Version: 0.5.5
4
4
  //
5
5
  (function() {
6
6
 
@@ -0,0 +1,289 @@
1
+ /**
2
+ * Unobtrusive scripting adapter for jQuery
3
+ *
4
+ * Requires jQuery 1.4.4 or later.
5
+ * https://github.com/rails/jquery-ujs
6
+
7
+ * Uploading file using rails.js
8
+ * =============================
9
+ *
10
+ * By default, browsers do not allow files to be uploaded via AJAX. As a result, if there are any non-blank file fields
11
+ * in the remote form, this adapter aborts the AJAX submission and allows the form to submit through standard means.
12
+ *
13
+ * The `ajax:aborted:file` event allows you to bind your own handler to process the form submission however you wish.
14
+ *
15
+ * Ex:
16
+ * $('form').live('ajax:aborted:file', function(event, elements){
17
+ * // Implement own remote file-transfer handler here for non-blank file inputs passed in `elements`.
18
+ * // Returning false in this handler tells rails.js to disallow standard form submission
19
+ * return false;
20
+ * });
21
+ *
22
+ * The `ajax:aborted:file` event is fired when a file-type input is detected with a non-blank value.
23
+ *
24
+ * Third-party tools can use this hook to detect when an AJAX file upload is attempted, and then use
25
+ * techniques like the iframe method to upload the file instead.
26
+ *
27
+ * Required fields in rails.js
28
+ * ===========================
29
+ *
30
+ * If any blank required inputs (required="required") are detected in the remote form, the whole form submission
31
+ * is canceled. Note that this is unlike file inputs, which still allow standard (non-AJAX) form submission.
32
+ *
33
+ * The `ajax:aborted:required` event allows you to bind your own handler to inform the user of blank required inputs.
34
+ *
35
+ * !! Note that Opera does not fire the form's submit event if there are blank required inputs, so this event may never
36
+ * get fired in Opera. This event is what causes other browsers to exhibit the same submit-aborting behavior.
37
+ *
38
+ * Ex:
39
+ * $('form').live('ajax:aborted:required', function(event, elements){
40
+ * // Returning false in this handler tells rails.js to submit the form anyway.
41
+ * // The blank required inputs are passed to this function in `elements`.
42
+ * return ! confirm("Would you like to submit the form with missing info?");
43
+ * });
44
+ */
45
+
46
+ (function($) {
47
+ // Shorthand to make it a little easier to call public rails functions from within rails.js
48
+ var rails;
49
+
50
+ $.rails = rails = {
51
+ // Link elements bound by jquery-ujs
52
+ linkClickSelector: 'a[data-confirm], a[data-method], a[data-remote]',
53
+
54
+ // Form elements bound by jquery-ujs
55
+ formSubmitSelector: 'form',
56
+
57
+ // Form input elements bound by jquery-ujs
58
+ formInputClickSelector: 'form input[type=submit], form input[type=image], form button[type=submit], form button:not([type])',
59
+
60
+ // Form input elements disabled during form submission
61
+ disableSelector: 'input[data-disable-with], button[data-disable-with], textarea[data-disable-with]',
62
+
63
+ // Form input elements re-enabled after form submission
64
+ enableSelector: 'input[data-disable-with]:disabled, button[data-disable-with]:disabled, textarea[data-disable-with]:disabled',
65
+
66
+ // Form required input elements
67
+ requiredInputSelector: 'input[name][required],textarea[name][required]',
68
+
69
+ // Form file input elements
70
+ fileInputSelector: 'input:file',
71
+
72
+ // Make sure that every Ajax request sends the CSRF token
73
+ CSRFProtection: function(xhr) {
74
+ var token = $('meta[name="csrf-token"]').attr('content');
75
+ if (token) xhr.setRequestHeader('X-CSRF-Token', token);
76
+ },
77
+
78
+ // Triggers an event on an element and returns false if the event result is false
79
+ fire: function(obj, name, data) {
80
+ var event = $.Event(name);
81
+ obj.trigger(event, data);
82
+ return event.result !== false;
83
+ },
84
+
85
+ // Submits "remote" forms and links with ajax
86
+ handleRemote: function(element) {
87
+ var method, url, data,
88
+ dataType = element.data('type') || ($.ajaxSettings && $.ajaxSettings.dataType);
89
+
90
+ if (rails.fire(element, 'ajax:before')) {
91
+
92
+ if (element.is('form')) {
93
+ method = element.attr('method');
94
+ url = element.attr('action');
95
+ data = element.serializeArray();
96
+ // memoized value from clicked submit button
97
+ var button = element.data('ujs:submit-button');
98
+ if (button) {
99
+ data.push(button);
100
+ element.data('ujs:submit-button', null);
101
+ }
102
+ } else {
103
+ method = element.data('method');
104
+ url = element.attr('href');
105
+ data = null;
106
+ }
107
+
108
+ $.ajax({
109
+ url: url, type: method || 'GET', data: data, dataType: dataType,
110
+ // stopping the "ajax:beforeSend" event will cancel the ajax request
111
+ beforeSend: function(xhr, settings) {
112
+ if (settings.dataType === undefined) {
113
+ xhr.setRequestHeader('accept', '*/*;q=0.5, ' + settings.accepts.script);
114
+ }
115
+ return rails.fire(element, 'ajax:beforeSend', [xhr, settings]);
116
+ },
117
+ success: function(data, status, xhr) {
118
+ element.trigger('ajax:success', [data, status, xhr]);
119
+ },
120
+ complete: function(xhr, status) {
121
+ element.trigger('ajax:complete', [xhr, status]);
122
+ },
123
+ error: function(xhr, status, error) {
124
+ element.trigger('ajax:error', [xhr, status, error]);
125
+ }
126
+ });
127
+ }
128
+ },
129
+
130
+ // Handles "data-method" on links such as:
131
+ // <a href="/users/5" data-method="delete" rel="nofollow" data-confirm="Are you sure?">Delete</a>
132
+ handleMethod: function(link) {
133
+ var href = link.attr('href'),
134
+ method = link.data('method'),
135
+ csrf_token = $('meta[name=csrf-token]').attr('content'),
136
+ csrf_param = $('meta[name=csrf-param]').attr('content'),
137
+ form = $('<form method="post" action="' + href + '"></form>'),
138
+ metadata_input = '<input name="_method" value="' + method + '" type="hidden" />';
139
+
140
+ if (csrf_param !== undefined && csrf_token !== undefined) {
141
+ metadata_input += '<input name="' + csrf_param + '" value="' + csrf_token + '" type="hidden" />';
142
+ }
143
+
144
+ form.hide().append(metadata_input).appendTo('body');
145
+ form.submit();
146
+ },
147
+
148
+ /* Disables form elements:
149
+ - Caches element value in 'ujs:enable-with' data store
150
+ - Replaces element text with value of 'data-disable-with' attribute
151
+ - Adds disabled=disabled attribute
152
+ */
153
+ disableFormElements: function(form) {
154
+ form.find(rails.disableSelector).each(function() {
155
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
156
+ element.data('ujs:enable-with', element[method]());
157
+ element[method](element.data('disable-with'));
158
+ element.attr('disabled', 'disabled');
159
+ });
160
+ },
161
+
162
+ /* Re-enables disabled form elements:
163
+ - Replaces element text with cached value from 'ujs:enable-with' data store (created in `disableFormElements`)
164
+ - Removes disabled attribute
165
+ */
166
+ enableFormElements: function(form) {
167
+ form.find(rails.enableSelector).each(function() {
168
+ var element = $(this), method = element.is('button') ? 'html' : 'val';
169
+ if (element.data('ujs:enable-with')) element[method](element.data('ujs:enable-with'));
170
+ element.removeAttr('disabled');
171
+ });
172
+ },
173
+
174
+ // If message provided in 'data-confirm' attribute, fires `confirm` event and returns result of confirm dialog.
175
+ // Attaching a handler to the element's `confirm` event that returns false cancels the confirm dialog.
176
+ allowAction: function(element) {
177
+ var message = element.data('confirm');
178
+ return !message || (rails.fire(element, 'confirm') && confirm(message));
179
+ },
180
+
181
+ // Helper function which checks for blank inputs in a form that match the specified CSS selector
182
+ blankInputs: function(form, specifiedSelector, nonBlank) {
183
+ var inputs = $(), input,
184
+ selector = specifiedSelector || 'input,textarea';
185
+ form.find(selector).each(function() {
186
+ input = $(this);
187
+ // Collect non-blank inputs if nonBlank option is true, otherwise, collect blank inputs
188
+ if (nonBlank ? input.val() : !input.val()) {
189
+ inputs = inputs.add(input);
190
+ }
191
+ });
192
+ return inputs.length ? inputs : false;
193
+ },
194
+
195
+ // Helper function which checks for non-blank inputs in a form that match the specified CSS selector
196
+ nonBlankInputs: function(form, specifiedSelector) {
197
+ return rails.blankInputs(form, specifiedSelector, true); // true specifies nonBlank
198
+ },
199
+
200
+ // Helper function, needed to provide consistent behavior in IE
201
+ stopEverything: function(e) {
202
+ e.stopImmediatePropagation();
203
+ return false;
204
+ },
205
+
206
+ // find all the submit events directly bound to the form and
207
+ // manually invoke them. If anyone returns false then stop the loop
208
+ callFormSubmitBindings: function(form) {
209
+ var events = form.data('events'), continuePropagation = true;
210
+ if (events !== undefined && events['submit'] !== undefined) {
211
+ $.each(events['submit'], function(i, obj){
212
+ if (typeof obj.handler === 'function') return continuePropagation = obj.handler(obj.data);
213
+ });
214
+ }
215
+ return continuePropagation;
216
+ }
217
+ };
218
+
219
+ // ajaxPrefilter is a jQuery 1.5 feature
220
+ if ('ajaxPrefilter' in $) {
221
+ $.ajaxPrefilter(function(options, originalOptions, xhr){ rails.CSRFProtection(xhr); });
222
+ } else {
223
+ $(document).ajaxSend(function(e, xhr){ rails.CSRFProtection(xhr); });
224
+ }
225
+
226
+ $(rails.linkClickSelector).live('click.rails', function(e) {
227
+ var link = $(this);
228
+ if (!rails.allowAction(link)) return rails.stopEverything(e);
229
+
230
+ if (link.data('remote') !== undefined) {
231
+ rails.handleRemote(link);
232
+ return false;
233
+ } else if (link.data('method')) {
234
+ rails.handleMethod(link);
235
+ return false;
236
+ }
237
+ });
238
+
239
+ $(rails.formSubmitSelector).live('submit.rails', function(e) {
240
+ var form = $(this),
241
+ remote = form.data('remote') !== undefined,
242
+ blankRequiredInputs = rails.blankInputs(form, rails.requiredInputSelector),
243
+ nonBlankFileInputs = rails.nonBlankInputs(form, rails.fileInputSelector);
244
+
245
+ if (!rails.allowAction(form)) return rails.stopEverything(e);
246
+
247
+ // skip other logic when required values are missing or file upload is present
248
+ if (blankRequiredInputs && rails.fire(form, 'ajax:aborted:required', [blankRequiredInputs])) {
249
+ return !remote;
250
+ }
251
+
252
+ if (remote) {
253
+ if (nonBlankFileInputs) {
254
+ return rails.fire(form, 'ajax:aborted:file', [nonBlankFileInputs]);
255
+ }
256
+
257
+ // If browser does not support submit bubbling, then this live-binding will be called before direct
258
+ // bindings. Therefore, we should directly call any direct bindings before remotely submitting form.
259
+ if (!$.support.submitBubbles && rails.callFormSubmitBindings(form) === false) return rails.stopEverything(e);
260
+
261
+ rails.handleRemote(form);
262
+ return false;
263
+ } else {
264
+ // slight timeout so that the submit button gets properly serialized
265
+ setTimeout(function(){ rails.disableFormElements(form); }, 13);
266
+ }
267
+ });
268
+
269
+ $(rails.formInputClickSelector).live('click.rails', function(event) {
270
+ var button = $(this);
271
+
272
+ if (!rails.allowAction(button)) return rails.stopEverything(event);
273
+
274
+ // register the pressed submit button
275
+ var name = button.attr('name'),
276
+ data = name ? {name:name, value:button.val()} : null;
277
+
278
+ button.closest('form').data('ujs:submit-button', data);
279
+ });
280
+
281
+ $(rails.formSubmitSelector).live('ajax:beforeSend.rails', function(event) {
282
+ if (this == event.target) rails.disableFormElements($(this));
283
+ });
284
+
285
+ $(rails.formSubmitSelector).live('ajax:complete.rails', function(event) {
286
+ if (this == event.target) rails.enableFormElements($(this));
287
+ });
288
+
289
+ })( jQuery );