active_admin_jcrop 0.0.2.alpha → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b507737de7d3ae760a816e3e0778e075514966b
4
- data.tar.gz: 073e037afd29c16b7c68289bcaa1730a24c5e43e
3
+ metadata.gz: 4c3e39b5e60f43769fbff60750d0b856f7af024e
4
+ data.tar.gz: 7d3377bb521eb54528316a9dfd3d2bb7a6972b86
5
5
  SHA512:
6
- metadata.gz: 2e48052bdca036eab391e30e89a7d10fe9156549af27b0bea381d2698a016623f4d499e896d1263b50f2bf5a805e6b289d81cf7346c60b232f62832b84180f39
7
- data.tar.gz: 83d3e2432b49608279955da2e901140f886f82fe18f423d41840138c30a9e9489845c0d3b6befbb719b654e02c5468bdeb2ddfd747ba35a63a20a48e80a568b4
6
+ metadata.gz: 8c094344e92da72037c6887a8a6bd79a6e695ea10bdcf3e8bb7239fa97b59b1e9375c0bbe84245d1b15dee53e4144748938cd455e80a609f44a3b48e9e8b9d32
7
+ data.tar.gz: 7205d7d0e048a19552a64805edf4fe5740a70ddfef19f56aa2639e412a448949c5a42dbb66262dfd389012a4087c623598ae23d2519aab71a72e586181bda751
@@ -4,6 +4,9 @@ window.active_admin_jcrop =
4
4
  $('.crop_modal_open').click ->
5
5
  content = $(this).parent().find('.crop_modal_content').clone()
6
6
  image = content.find('img.cropping_image')
7
+ active_admin_jcrop.buttons_text =
8
+ save_cropped_image: image.data('translateSaveCroppedImage')
9
+ cancel: image.data('translateCancel')
7
10
  active_admin_jcrop.cropper =
8
11
  object_class: image.data('objectClass')
9
12
  object_id: image.data('objectId')
@@ -19,26 +22,32 @@ window.active_admin_jcrop =
19
22
  at: "center",
20
23
  of: window
21
24
  }
22
- buttons:
23
- 'Crop Image': ->
24
-
25
- cropper = active_admin_jcrop.cropper
26
- $.ajax
27
- type: 'PUT'
28
- url: cropper.jcropper_url
29
- data:
30
- image_data: cropper
31
- success: ->
32
- console.log('nois')
33
- error: ->
34
- alert('There was an error while cropping the image')
35
- $(@).dialog('close')
36
- Cancel: ->
37
- $(@).dialog('close').remove()
38
-
39
- image.Jcrop
40
- onSelect: update_cropper
41
- onChange: update_cropper
25
+ buttons: [
26
+ {
27
+ text: active_admin_jcrop.buttons_text.save_cropped_image
28
+ click: ->
29
+ text: 'aews'
30
+ cropper = active_admin_jcrop.cropper
31
+ $.ajax
32
+ type: 'PUT'
33
+ url: cropper.jcropper_url
34
+ data:
35
+ image_data: cropper
36
+ success: ->
37
+ console.log('nois')
38
+ error: ->
39
+ alert('There was an error while cropping the image')
40
+ $(@).dialog('close')
41
+ }
42
+ {
43
+ text: active_admin_jcrop.buttons_text.cancel
44
+ click: ->
45
+ $(@).dialog('close').remove()
46
+
47
+ }
48
+ ]
49
+ options = $.extend {onSelect: update_cropper, onChange: update_cropper }, image.data('jcropOptions')
50
+ image.Jcrop(options)
42
51
 
43
52
  update_cropper = (coords) ->
44
53
  active_admin_jcrop.cropper.crop_x = coords.x
@@ -1,4 +1,4 @@
1
- <%= link_to "Crop Image", "#" , class: "button crop_modal_open" %>
1
+ <%= link_to I18n.t("active_admin.crop.open_crop_modal").titleize, "#" , class: "button crop_modal_open" %>
2
2
 
3
3
  <%= content_tag :div, class: "crop_modal_content" do %>
4
4
  <center>
@@ -6,7 +6,10 @@
6
6
  object_class: object.class.to_s.downcase,
7
7
  object_id: object.id,
8
8
  crop_field: field,
9
- jcropper_url: send("jcropper_admin_#{object.class.to_s.downcase}_path")
9
+ jcropper_url: send("jcropper_admin_#{object.class.to_s.downcase}_path"),
10
+ translate_save_cropped_image: I18n.t("active_admin.crop.save_cropped_image").titleize,
11
+ translate_cancel: I18n.t("active_admin.crop.cancel").titleize,
12
+ jcrop_options: jcrop_options.to_json
10
13
  }
11
14
  %>
12
15
  </center>
@@ -0,0 +1,6 @@
1
+ en:
2
+ active_admin:
3
+ crop:
4
+ open_crop_modal: Crop Image
5
+ save_cropped_image: Save Cropped Image
6
+ cancel: Cancel
@@ -0,0 +1,6 @@
1
+ pt-BR:
2
+ active_admin:
3
+ crop:
4
+ open_crop_modal: Cortar Imagem
5
+ save_cropped_image: Salvar Imagem Cortada
6
+ cancel: Cancelar
@@ -1,5 +1,5 @@
1
1
  if Gem::Specification::find_all_by_name('carrierwave').any?
2
- require 'asset_engine/carrier_wave'
2
+ require 'active_admin_jcrop/asset_engine/carrier_wave'
3
3
  elsif Gem::Specification::find_all_by_name('paperclip').any?
4
- require 'asset_engine/paperclip'
4
+ require 'active_admin_jcrop/asset_engine/paperclip'
5
5
  end
File without changes
File without changes
@@ -13,12 +13,7 @@ module ActiveAdminJcrop
13
13
  end
14
14
 
15
15
  def active_admin_crop!(params)
16
- if defined?(::CarrierWave)
17
- require 'asset_engine/carrier_wave'
18
- elsif defined?(::Paperclip)
19
- require 'asset_engine/paperclip'
20
- end
21
-
16
+
22
17
  CropFields.each {|f| self.send "#{f}=", params[f] }
23
18
 
24
19
  ::ActiveAdminJcrop::AssetEngine.crop!(self, self.crop_field) if self.active_admin_cropping?
File without changes
@@ -1,3 +1,3 @@
1
1
  module ActiveAdminJcrop
2
- VERSION = "0.0.2.alpha"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -1,8 +1,8 @@
1
1
  require "activeadmin"
2
- require "dsl"
3
- require 'asset_engine'
4
- require 'orm'
2
+ require "active_admin_jcrop/dsl"
3
+ require 'active_admin_jcrop/asset_engine'
4
+ require 'active_admin_jcrop/orm'
5
5
  require "formtastic/inputs/jcrop_input"
6
- require "engine"
7
- require "railtie"
8
- require 'image_helper'
6
+ require "active_admin_jcrop/engine"
7
+ require "active_admin_jcrop/railtie"
8
+ require 'active_admin_jcrop/image_helper'
@@ -1,6 +1,6 @@
1
1
  module Formtastic
2
2
  module Inputs
3
- class JcropInput < ::Formtastic::Inputs::FileInput
3
+ class JcropableInput < ::Formtastic::Inputs::FileInput
4
4
  include Base
5
5
 
6
6
  def to_html
@@ -9,18 +9,24 @@ module Formtastic
9
9
  builder.file_field(method, input_html_options) <<
10
10
  jcrop_feature
11
11
  end
12
- end
12
+ end
13
13
 
14
14
  private
15
15
 
16
16
  def jcrop_feature
17
- if @object.send(method).present?
18
- template.render(partial: "active_admin_jcrop/jcrop_modal", locals: {field: method, object: @object})
17
+ if @object.send(method).present?
18
+ template.render(partial: "active_admin_jcrop/jcrop_modal", locals: {field: method, object: @object, jcrop_options: jcrop_options})
19
19
  else
20
20
  ''
21
21
  end
22
22
  end
23
23
 
24
+ def jcrop_options
25
+ options[:jcrop_options] ||= {}
26
+ options[:jcrop_options].assert_valid_keys(:aspectRatio, :minSize, :maxSize, :setSelect, :bgColor, :bgOpacity)
27
+ options[:jcrop_options].reverse_merge!(setSelect: [0,0,100,100])
28
+ end
29
+
24
30
  end
25
31
  end
26
32
  end
@@ -4,7 +4,7 @@ ActiveAdmin.register Post do
4
4
 
5
5
  form do |f|
6
6
  f.inputs "Details" do
7
- f.input :image, as: :jcrop
7
+ f.input :image, as: :jcropable , jcrop_options: {aspectRatio: 1}
8
8
  end
9
9
  f.actions
10
10
  end