forked from oriolgual/silvia.cat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
_form.html.slim
66 lines (57 loc) · 1.77 KB
/
_form.html.slim
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
= simple_form_for [ :backend, resource ] do |f|
= f.input :name_ca, required: true
= f.input :name_es, required: true
= f.input :description_ca, as: :text
= f.input :description_es, as: :text
#illustration
= f.input :image
= f.hidden_field :image_cache
- if resource.image?
= f.hidden_field :thumbnail_coordinates
= image_tag(resource.image.url, id: 'image') if resource.image?
#thumb_container
= image_tag resource.image.url, id: 'thumb'
= f.association :category, collection: Category.all
= f.submit
javascript:
var jcrop_api;
function showPreview(coords)
{
var image = $('#image');
var thumb_container = $('#thumb_container');
var rx = thumb_container.width() / coords.w;
var ry = thumb_container.height() / coords.h;
$('#thumb').css({
width: Math.round(rx * image.width()) + 'px',
height: Math.round(ry * image.height()) + 'px',
marginLeft: '-' + Math.round(rx * coords.x) + 'px',
marginTop: '-' + Math.round(ry * coords.y) + 'px'
});
};
function update_form(coords) {
var json = JSON.stringify(coords);
var thumb_input = $('#illustration_thumbnail_coordinates')
thumb_input[0].value = json;
showPreview(coords);
}
-if resource.thumbnail_coordinates.blank?
javascript:
$(function(){
$('#image').Jcrop({
onChange: update_form,
onSelect: update_form,
aspectRatio: 1
});
});
-else
javascript:
$(function(){
$('#image').Jcrop({
onChange: update_form,
onSelect: update_form,
aspectRatio: 1
},function(){
this.setSelect([#{select_current_coordinates(resource.thumbnail_coordinates)}]);
showPreview(#{resource.thumbnail_coordinates.to_json.html_safe});
});
});