lolita-i18n 0.1.18 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "http://rubygems.org"
2
2
 
3
- gem "lolita", '3.1.18'
3
+ gem "lolita", '~>3.2.0.rc.6'
4
4
  gem "hiredis", "~> 0.3.1"
5
5
  gem "redis", "~> 2.2.2", :require => ["redis/connection/hiredis", "redis"]
6
6
  gem "yajl-ruby", "~> 1.0.0"
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.18
1
+ 0.2.0
@@ -0,0 +1,135 @@
1
+ class LolitaI18nCell
2
+
3
+ constructor: (@td) ->
4
+ @p = @td.find('p:first')
5
+
6
+ edit: ->
7
+ if @td.find('input').size() == 0
8
+ @key = @td.attr('data-key')
9
+ @locale = @td.attr('data-locale')
10
+ input = $('<textarea name="'+@key+'" />').html(@fix_quotes(@p.text().trim()))
11
+ input.css('width',@p.width()+'px').css('height', @p.height()+'px')
12
+ @p.html("")
13
+ @p.hide()
14
+ @td.append(input)
15
+ input.focus()
16
+ that = this
17
+
18
+ input.blur ->
19
+ that.value = input.val().trim()
20
+ input.remove()
21
+ that.add_spinner()
22
+ that.save()
23
+
24
+ input.keyup (e) ->
25
+ if e.keyCode == 27
26
+ input.trigger('blur')
27
+
28
+ save: ->
29
+ that = this
30
+ $.ajax
31
+ type: 'PUT'
32
+ url: '/lolita/i18n/' + @locale + '.' + that.key
33
+ data: {translation: that.value}
34
+ dataType: 'json'
35
+ success: (data) ->
36
+ if data.error
37
+ alert "Error saving translation " + that.key
38
+ that.remove_spinner()
39
+
40
+ add_spinner: ->
41
+ opts =
42
+ lines: 10
43
+ length: 3
44
+ width: 2
45
+ radius: 5,
46
+ color: '#000'
47
+ speed: 1
48
+ trail: 20
49
+ shadow: false
50
+
51
+ @spinner = Spinner(opts).spin()
52
+ @td.prepend(@spinner.el)
53
+ $(@spinner.el).css('top',($(@spinner.el).parent().height() / 2)+ 'px').css('left','5px').css('clear','both')
54
+
55
+ remove_spinner: ->
56
+ @spinner.stop()
57
+ @p.text(@value)
58
+ @p.show()
59
+
60
+ fix_quotes: (value) ->
61
+ value.replace(/\'/g, "&#39;").replace(/\"/g, "&#34;")
62
+
63
+ class LolitaTranslate
64
+
65
+ constructor: (@button)->
66
+ @url = @button.attr('data-url')
67
+ @locale = @button.attr('data-locale')
68
+ @add_spinner()
69
+ @translate()
70
+
71
+ translate: ->
72
+ that = this
73
+
74
+ $.ajax
75
+ type: 'PUT'
76
+ url: @url
77
+ data: {active_locale: @locale}
78
+ dataType: 'json'
79
+ success: (data) ->
80
+ if data.errors.length > 0
81
+ alert("Errors\n\n" + data.errors.join("\n"))
82
+ that.remove_spinner()
83
+ if data.translated > 0
84
+ window.location.reload()
85
+ else
86
+ that.remove_spinner()
87
+ error: (request,error) ->
88
+ alert "Error 500"
89
+ that.remove_spinner()
90
+
91
+ add_spinner: ->
92
+ opts =
93
+ lines: 10
94
+ length: 3
95
+ width: 2
96
+ radius: 5
97
+ color: '#000'
98
+ speed: 1
99
+ trail: 5
100
+ shadow: false
101
+
102
+ @spinner = Spinner(opts).spin()
103
+ @button.append(@spinner.el)
104
+ @button.addClass('loading')
105
+ @button.attr('disabled',true)
106
+ $(@spinner.el).css('position', 'absolute').css('top','17px').css('left','16px')
107
+
108
+ remove_spinner: ->
109
+ @spinner.stop()
110
+ @button.removeClass('loading')
111
+ @button.attr('disabled',false)
112
+
113
+ params = (name) ->
114
+ decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search)||[1,null])[1])
115
+
116
+ $ ->
117
+ $('.list td p').click ->
118
+ cell = new LolitaI18nCell $(this).parent()
119
+ cell.edit()
120
+ $('.list td span.hint').click ->
121
+ cell = new LolitaI18nCell $(this).parent()
122
+ cell.edit()
123
+ $('#active_locale').change ->
124
+ show_untranslated = if params('show_untranslated') == "null" then "" else "&show_untranslated=true"
125
+ window.location.href = "?active_locale=" + $(this).val() + show_untranslated
126
+ $('button.translate:first').click ->
127
+ if confirm('Are you shure?')
128
+ new LolitaTranslate $(this)
129
+ $('#show_untranslated').change ->
130
+ active_locale = if params('active_locale') == "null" then "" else "active_locale=" + params('active_locale')
131
+ if $(this).attr('checked')
132
+ window.location.href = "?show_untranslated=true&" + active_locale
133
+ else
134
+ window.location.href = "?" + active_locale
135
+
@@ -52,7 +52,7 @@ div.list div.actions {
52
52
  position: relative;
53
53
  padding-left: 30px;
54
54
  height: 34px;
55
- background-image: url('/images/lolita/i18n/google_translate_icon.png');
55
+ background-image: url(image-path('lolita/i18n/google_translate_icon.png'));
56
56
  background-position: 5px 5px;
57
57
  background-repeat: no-repeat;
58
58
  box-shadow: inset 0 0 1px 1px #eaeaea;
@@ -1,9 +1,7 @@
1
1
  - content_for :style do
2
2
  = stylesheet_link_tag "lolita/i18n/application", :media => "screen,projection"
3
3
  - content_for :script do
4
- =# javascript_include_tag "lolita/i18n/application"
5
- = javascript_include_tag "lolita/i18n/i18n.js"
6
- = javascript_include_tag "lolita/i18n/spin.min.js"
4
+ = javascript_include_tag "lolita/i18n/application"
7
5
  .box.i18n-bo
8
6
  .boxtitle
9
7
  %h1.black= ::I18n.t('lolita-i18n.title', :default => "Static content translation")
@@ -30,7 +30,7 @@ module Lolita
30
30
  if value.blank?
31
31
  del key
32
32
  else
33
- if Lolita.i18n.backend.store_translations(locale,{translation_key=>value},:escape=>false)
33
+ if Lolita::I18n.backend.store_translations(locale,{translation_key=>value},:escape=>false)
34
34
  Lolita::I18n::GoogleTranslate.del_translation locale, translation_key
35
35
  true
36
36
  else
@@ -40,7 +40,7 @@ module Lolita
40
40
  end
41
41
 
42
42
  def del key
43
- Lolita.i18n.store.del key
43
+ Lolita::I18n.store.del key
44
44
  end
45
45
 
46
46
  def locale(key)
data/lib/lolita-i18n.rb CHANGED
@@ -20,7 +20,7 @@ module Lolita
20
20
  autoload :Backend, 'lolita-i18n/backend'
21
21
  autoload :GoogleTranslate, 'lolita-i18n/google_translate'
22
22
 
23
-
23
+
24
24
  class Configuration
25
25
 
26
26
  attr_accessor :yaml_backend
@@ -37,10 +37,10 @@ module Lolita
37
37
 
38
38
  def store=(possible_store)
39
39
  @store = if possible_store.is_a?(Hash)
40
- Redis.new(possible_store)
41
- else
42
- possible_store
43
- end
40
+ Redis.new(possible_store)
41
+ else
42
+ possible_store
43
+ end
44
44
  @store
45
45
  end
46
46
 
@@ -84,14 +84,7 @@ Lolita.scope.extend(LolitaI18nConfiguration)
84
84
  Lolita.after_setup do
85
85
  Lolita.i18n.yaml_backend = ::I18n.backend
86
86
  Lolita.i18n.include_modules
87
- begin
88
- r = Redis.new
89
- r.ping
90
- ::I18n.backend = Lolita.i18n.initialize_chain
91
- rescue Errno::ECONNREFUSED => e
92
- warn "Warning: Lolita was unable to connect to Redis DB: #{e}"
93
- end
94
-
87
+ ::I18n.backend = Lolita.i18n.initialize_chain
95
88
  end
96
89
 
97
90
  require 'lolita-i18n/module'
@@ -102,15 +95,16 @@ end
102
95
 
103
96
  Lolita.after_routes_loaded do
104
97
  if tree=Lolita::Navigation::Tree[:"left_side_navigation"]
105
- unless tree.branches.detect { |b| b.title=="System" }
106
- branch=tree.append(nil, :title=>"System")
98
+ unless tree.branches.detect{|b| b.title=="System"}
99
+ branch=tree.append(nil,:title=>"System")
107
100
  #mapping=Lolita::Mapping.new(:i18n_index,:singular=>:i18n,:class_name=>Object,:controller=>"lolita/i18n")
108
- branch.append(Object, :title=>"I18n", :url=>Proc.new { |view, branch|
101
+ branch.append(Object,:title=>"I18n",:url=>Proc.new{|view,branch|
109
102
  view.send(:lolita_i18n_index_path)
110
- }, :active=>Proc.new { |view, parent_branch, branch|
103
+ }, :active=>Proc.new{|view,parent_branch,branch|
111
104
  params=view.send(:params)
112
105
  params[:controller].to_s.match(/lolita\/i18n/)
113
106
  })
114
107
  end
115
108
  end
116
109
  end
110
+
data/lolita-i18n.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "lolita-i18n"
8
- s.version = "0.1.18"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["ITHouse (Latvia)", "Arturs Meisters", "Gatis Tomsons"]
12
- s.date = "2011-12-09"
12
+ s.date = "2011-11-11"
13
13
  s.description = "Lolita plugin, that enables .yml files management from administrative interface. Also faster access to translations, that DB store"
14
14
  s.email = "support@ithouse.lv"
15
15
  s.extra_rdoc_files = [
@@ -25,6 +25,11 @@ Gem::Specification.new do |s|
25
25
  "README.md",
26
26
  "Rakefile",
27
27
  "VERSION",
28
+ "app/assets/images/lolita/i18n/google_translate_icon.png",
29
+ "app/assets/javascripts/lolita/i18n/application.js",
30
+ "app/assets/javascripts/lolita/i18n/i18n.js.coffee",
31
+ "app/assets/javascripts/lolita/i18n/spin.min.js",
32
+ "app/assets/stylesheets/lolita/i18n/application.scss",
28
33
  "app/controllers/lolita/i18n_controller.rb",
29
34
  "app/helpers/lolita/i18n_helper.rb",
30
35
  "app/views/lolita/i18n/index.html.haml",
@@ -37,11 +42,6 @@ Gem::Specification.new do |s|
37
42
  "lib/lolita-i18n/module.rb",
38
43
  "lib/lolita-i18n/rails.rb",
39
44
  "lolita-i18n.gemspec",
40
- "public/images/lolita/i18n/google_translate_icon.png",
41
- "public/javascripts/lolita/i18n/application.js",
42
- "public/javascripts/lolita/i18n/i18n.js",
43
- "public/javascripts/lolita/i18n/spin.min.js",
44
- "public/stylesheets/lolita/i18n/application.css",
45
45
  "spec/controllers/lolita/i18n_controller_spec.rb",
46
46
  "spec/lolita-i18n/backend_spec.rb",
47
47
  "spec/lolita-i18n/google_translate_spec.rb",
@@ -57,7 +57,7 @@ Gem::Specification.new do |s|
57
57
  s.homepage = "http://github.com/ithouse/lolita-i18n"
58
58
  s.licenses = ["MIT"]
59
59
  s.require_paths = ["lib"]
60
- s.rubygems_version = "1.8.11"
60
+ s.rubygems_version = "1.8.10"
61
61
  s.summary = "Lolita plugin, that enables .yml management"
62
62
  s.test_files = [
63
63
  "spec/controllers/lolita/i18n_controller_spec.rb",
@@ -75,7 +75,7 @@ Gem::Specification.new do |s|
75
75
  s.specification_version = 3
76
76
 
77
77
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
78
- s.add_runtime_dependency(%q<lolita>, ["= 3.1.18"])
78
+ s.add_runtime_dependency(%q<lolita>, ["~> 3.2.0.rc.6"])
79
79
  s.add_runtime_dependency(%q<hiredis>, ["~> 0.3.1"])
80
80
  s.add_runtime_dependency(%q<redis>, ["~> 2.2.2"])
81
81
  s.add_runtime_dependency(%q<yajl-ruby>, ["~> 1.0.0"])
@@ -85,7 +85,7 @@ Gem::Specification.new do |s|
85
85
  s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
86
86
  s.add_development_dependency(%q<rcov>, [">= 0"])
87
87
  else
88
- s.add_dependency(%q<lolita>, ["= 3.1.18"])
88
+ s.add_dependency(%q<lolita>, ["~> 3.2.0.rc.6"])
89
89
  s.add_dependency(%q<hiredis>, ["~> 0.3.1"])
90
90
  s.add_dependency(%q<redis>, ["~> 2.2.2"])
91
91
  s.add_dependency(%q<yajl-ruby>, ["~> 1.0.0"])
@@ -96,7 +96,7 @@ Gem::Specification.new do |s|
96
96
  s.add_dependency(%q<rcov>, [">= 0"])
97
97
  end
98
98
  else
99
- s.add_dependency(%q<lolita>, ["= 3.1.18"])
99
+ s.add_dependency(%q<lolita>, ["~> 3.2.0.rc.6"])
100
100
  s.add_dependency(%q<hiredis>, ["~> 0.3.1"])
101
101
  s.add_dependency(%q<redis>, ["~> 2.2.2"])
102
102
  s.add_dependency(%q<yajl-ruby>, ["~> 1.0.0"])
@@ -17,7 +17,7 @@ describe Lolita::I18n::Backend do
17
17
  Lolita::I18n::Backend.set("en.test-key","Hello")
18
18
  Lolita::I18n::Backend.get("en.test-key")[:value].should == "Hello"
19
19
  Lolita::I18n::Backend.set("en.test-key","")
20
- Lolita.i18n.store.get("en.test-key").should be_nil
20
+ Lolita::I18n.store.get("en.test-key").should be_nil
21
21
  end
22
22
 
23
23
  it "should get translation into DB" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lolita-i18n
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,22 +11,22 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2011-12-09 00:00:00.000000000Z
14
+ date: 2011-11-11 00:00:00.000000000Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: lolita
18
- requirement: &19266740 !ruby/object:Gem::Requirement
18
+ requirement: &82640050 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
- - - =
21
+ - - ~>
22
22
  - !ruby/object:Gem::Version
23
- version: 3.1.18
23
+ version: 3.2.0.rc.6
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: *19266740
26
+ version_requirements: *82640050
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hiredis
29
- requirement: &19258960 !ruby/object:Gem::Requirement
29
+ requirement: &82639690 !ruby/object:Gem::Requirement
30
30
  none: false
31
31
  requirements:
32
32
  - - ~>
@@ -34,10 +34,10 @@ dependencies:
34
34
  version: 0.3.1
35
35
  type: :runtime
36
36
  prerelease: false
37
- version_requirements: *19258960
37
+ version_requirements: *82639690
38
38
  - !ruby/object:Gem::Dependency
39
39
  name: redis
40
- requirement: &19257140 !ruby/object:Gem::Requirement
40
+ requirement: &82639370 !ruby/object:Gem::Requirement
41
41
  none: false
42
42
  requirements:
43
43
  - - ~>
@@ -45,10 +45,10 @@ dependencies:
45
45
  version: 2.2.2
46
46
  type: :runtime
47
47
  prerelease: false
48
- version_requirements: *19257140
48
+ version_requirements: *82639370
49
49
  - !ruby/object:Gem::Dependency
50
50
  name: yajl-ruby
51
- requirement: &19255580 !ruby/object:Gem::Requirement
51
+ requirement: &82639100 !ruby/object:Gem::Requirement
52
52
  none: false
53
53
  requirements:
54
54
  - - ~>
@@ -56,10 +56,10 @@ dependencies:
56
56
  version: 1.0.0
57
57
  type: :runtime
58
58
  prerelease: false
59
- version_requirements: *19255580
59
+ version_requirements: *82639100
60
60
  - !ruby/object:Gem::Dependency
61
61
  name: easy_translate
62
- requirement: &19253800 !ruby/object:Gem::Requirement
62
+ requirement: &82638790 !ruby/object:Gem::Requirement
63
63
  none: false
64
64
  requirements:
65
65
  - - ~>
@@ -67,10 +67,10 @@ dependencies:
67
67
  version: 0.2.1
68
68
  type: :runtime
69
69
  prerelease: false
70
- version_requirements: *19253800
70
+ version_requirements: *82638790
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: shoulda
73
- requirement: &19252340 !ruby/object:Gem::Requirement
73
+ requirement: &82638490 !ruby/object:Gem::Requirement
74
74
  none: false
75
75
  requirements:
76
76
  - - ! '>='
@@ -78,10 +78,10 @@ dependencies:
78
78
  version: '0'
79
79
  type: :development
80
80
  prerelease: false
81
- version_requirements: *19252340
81
+ version_requirements: *82638490
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: bundler
84
- requirement: &19214100 !ruby/object:Gem::Requirement
84
+ requirement: &82638220 !ruby/object:Gem::Requirement
85
85
  none: false
86
86
  requirements:
87
87
  - - ~>
@@ -89,10 +89,10 @@ dependencies:
89
89
  version: 1.0.0
90
90
  type: :development
91
91
  prerelease: false
92
- version_requirements: *19214100
92
+ version_requirements: *82638220
93
93
  - !ruby/object:Gem::Dependency
94
94
  name: jeweler
95
- requirement: &19184600 !ruby/object:Gem::Requirement
95
+ requirement: &82637680 !ruby/object:Gem::Requirement
96
96
  none: false
97
97
  requirements:
98
98
  - - ~>
@@ -100,10 +100,10 @@ dependencies:
100
100
  version: 1.5.2
101
101
  type: :development
102
102
  prerelease: false
103
- version_requirements: *19184600
103
+ version_requirements: *82637680
104
104
  - !ruby/object:Gem::Dependency
105
105
  name: rcov
106
- requirement: &19170920 !ruby/object:Gem::Requirement
106
+ requirement: &82637180 !ruby/object:Gem::Requirement
107
107
  none: false
108
108
  requirements:
109
109
  - - ! '>='
@@ -111,7 +111,7 @@ dependencies:
111
111
  version: '0'
112
112
  type: :development
113
113
  prerelease: false
114
- version_requirements: *19170920
114
+ version_requirements: *82637180
115
115
  description: Lolita plugin, that enables .yml files management from administrative
116
116
  interface. Also faster access to translations, that DB store
117
117
  email: support@ithouse.lv
@@ -129,6 +129,11 @@ files:
129
129
  - README.md
130
130
  - Rakefile
131
131
  - VERSION
132
+ - app/assets/images/lolita/i18n/google_translate_icon.png
133
+ - app/assets/javascripts/lolita/i18n/application.js
134
+ - app/assets/javascripts/lolita/i18n/i18n.js.coffee
135
+ - app/assets/javascripts/lolita/i18n/spin.min.js
136
+ - app/assets/stylesheets/lolita/i18n/application.scss
132
137
  - app/controllers/lolita/i18n_controller.rb
133
138
  - app/helpers/lolita/i18n_helper.rb
134
139
  - app/views/lolita/i18n/index.html.haml
@@ -141,11 +146,6 @@ files:
141
146
  - lib/lolita-i18n/module.rb
142
147
  - lib/lolita-i18n/rails.rb
143
148
  - lolita-i18n.gemspec
144
- - public/images/lolita/i18n/google_translate_icon.png
145
- - public/javascripts/lolita/i18n/application.js
146
- - public/javascripts/lolita/i18n/i18n.js
147
- - public/javascripts/lolita/i18n/spin.min.js
148
- - public/stylesheets/lolita/i18n/application.css
149
149
  - spec/controllers/lolita/i18n_controller_spec.rb
150
150
  - spec/lolita-i18n/backend_spec.rb
151
151
  - spec/lolita-i18n/google_translate_spec.rb
@@ -170,6 +170,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
170
170
  - - ! '>='
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
+ segments:
174
+ - 0
175
+ hash: -153498191
173
176
  required_rubygems_version: !ruby/object:Gem::Requirement
174
177
  none: false
175
178
  requirements:
@@ -178,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
178
181
  version: '0'
179
182
  requirements: []
180
183
  rubyforge_project:
181
- rubygems_version: 1.8.11
184
+ rubygems_version: 1.8.10
182
185
  signing_key:
183
186
  specification_version: 3
184
187
  summary: Lolita plugin, that enables .yml management
@@ -1,169 +0,0 @@
1
- var LolitaI18nCell, LolitaTranslate, params;
2
- LolitaI18nCell = (function() {
3
- function LolitaI18nCell(td) {
4
- this.td = td;
5
- this.p = this.td.find('p:first');
6
- }
7
- LolitaI18nCell.prototype.edit = function() {
8
- var input, that;
9
- if (this.td.find('input').size() === 0) {
10
- this.key = this.td.attr('data-key');
11
- this.locale = this.td.attr('data-locale');
12
- input = $('<textarea name="' + this.key + '" />').html(this.fix_quotes(this.p.text().trim()));
13
- input.css('width', this.p.width() + 'px').css('height', this.p.height() + 'px');
14
- this.p.html("");
15
- this.p.hide();
16
- this.td.append(input);
17
- input.focus();
18
- that = this;
19
- input.blur(function() {
20
- that.value = input.val().trim();
21
- input.remove();
22
- that.add_spinner();
23
- return that.save();
24
- });
25
- return input.keyup(function(e) {
26
- if (e.keyCode === 27) {
27
- return input.trigger('blur');
28
- }
29
- });
30
- }
31
- };
32
- LolitaI18nCell.prototype.save = function() {
33
- var that;
34
- that = this;
35
- return $.ajax({
36
- type: 'PUT',
37
- url: '/lolita/i18n/' + this.locale + '.' + that.key,
38
- data: {
39
- translation: that.value
40
- },
41
- dataType: 'json',
42
- success: function(data) {
43
- if (data.error) {
44
- alert("Error saving translation " + that.key);
45
- }
46
- return that.remove_spinner();
47
- }
48
- });
49
- };
50
- LolitaI18nCell.prototype.add_spinner = function() {
51
- var opts;
52
- opts = {
53
- lines: 10,
54
- length: 3,
55
- width: 2,
56
- radius: 5,
57
- color: '#000',
58
- speed: 1,
59
- trail: 20,
60
- shadow: false
61
- };
62
- this.spinner = Spinner(opts).spin();
63
- this.td.prepend(this.spinner.el);
64
- return $(this.spinner.el).css('top', ($(this.spinner.el).parent().height() / 2) + 'px').css('left', '5px').css('clear', 'both');
65
- };
66
- LolitaI18nCell.prototype.remove_spinner = function() {
67
- this.spinner.stop();
68
- this.p.text(this.value);
69
- return this.p.show();
70
- };
71
- LolitaI18nCell.prototype.fix_quotes = function(value) {
72
- return value.replace(/\'/g, "&#39;").replace(/\"/g, "&#34;");
73
- };
74
- return LolitaI18nCell;
75
- })();
76
- LolitaTranslate = (function() {
77
- function LolitaTranslate(button) {
78
- this.button = button;
79
- this.url = this.button.attr('data-url');
80
- this.locale = this.button.attr('data-locale');
81
- this.add_spinner();
82
- this.translate();
83
- }
84
- LolitaTranslate.prototype.translate = function() {
85
- var that;
86
- that = this;
87
- return $.ajax({
88
- type: 'PUT',
89
- url: this.url,
90
- data: {
91
- active_locale: this.locale
92
- },
93
- dataType: 'json',
94
- success: function(data) {
95
- if (data.errors.length > 0) {
96
- alert("Errors\n\n" + data.errors.join("\n"));
97
- that.remove_spinner();
98
- }
99
- if (data.translated > 0) {
100
- return window.location.reload();
101
- } else {
102
- return that.remove_spinner();
103
- }
104
- },
105
- error: function(request, error) {
106
- alert("Error 500");
107
- return that.remove_spinner();
108
- }
109
- });
110
- };
111
- LolitaTranslate.prototype.add_spinner = function() {
112
- var opts;
113
- opts = {
114
- lines: 10,
115
- length: 3,
116
- width: 2,
117
- radius: 5,
118
- color: '#000',
119
- speed: 1,
120
- trail: 5,
121
- shadow: false
122
- };
123
- this.spinner = Spinner(opts).spin();
124
- this.button.append(this.spinner.el);
125
- this.button.addClass('loading');
126
- this.button.attr('disabled', true);
127
- return $(this.spinner.el).css('position', 'absolute').css('top', '17px').css('left', '16px');
128
- };
129
- LolitaTranslate.prototype.remove_spinner = function() {
130
- this.spinner.stop();
131
- this.button.removeClass('loading');
132
- return this.button.attr('disabled', false);
133
- };
134
- return LolitaTranslate;
135
- })();
136
- params = function(name) {
137
- return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [1, null])[1]);
138
- };
139
- $(function() {
140
- $('.list td p').click(function() {
141
- var cell;
142
- cell = new LolitaI18nCell($(this).parent());
143
- return cell.edit();
144
- });
145
- $('.list td span.hint').click(function() {
146
- var cell;
147
- cell = new LolitaI18nCell($(this).parent());
148
- return cell.edit();
149
- });
150
- $('#active_locale').change(function() {
151
- var show_untranslated;
152
- show_untranslated = params('show_untranslated') === "null" ? "" : "&show_untranslated=true";
153
- return window.location.href = "?active_locale=" + $(this).val() + show_untranslated;
154
- });
155
- $('button.translate:first').click(function() {
156
- if (confirm('Are you shure?')) {
157
- return new LolitaTranslate($(this));
158
- }
159
- });
160
- return $('#show_untranslated').change(function() {
161
- var active_locale;
162
- active_locale = params('active_locale') === "null" ? "" : "active_locale=" + params('active_locale');
163
- if ($(this).attr('checked')) {
164
- return window.location.href = "?show_untranslated=true&" + active_locale;
165
- } else {
166
- return window.location.href = "?" + active_locale;
167
- }
168
- });
169
- });