refinerycms-snippets 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/public/javascripts/page-snippet-picker.js +129 -0
- metadata +5 -3
@@ -0,0 +1,129 @@
|
|
1
|
+
$(document).ready(function(){
|
2
|
+
|
3
|
+
/**
|
4
|
+
* Class for handling everything between page and snippets
|
5
|
+
*/
|
6
|
+
var PageSnippet = {
|
7
|
+
processing: false,
|
8
|
+
content_holder: [], // html wrapper for all stuff
|
9
|
+
add_snippet: [], // add snippet anchor
|
10
|
+
inactive_snippets: [], // select box with inactive snippets on page
|
11
|
+
|
12
|
+
|
13
|
+
spinner_on: function () {
|
14
|
+
this.processing = true;
|
15
|
+
this.inactive_snippets.attr('disabled', 'disabled');
|
16
|
+
this.content_holder.css({opacity: 0.5});
|
17
|
+
},
|
18
|
+
|
19
|
+
spinner_off: function () {
|
20
|
+
this.content_holder.css({opacity: 1});
|
21
|
+
this.inactive_snippets.removeAttr('disabled');
|
22
|
+
this.processing = false;
|
23
|
+
},
|
24
|
+
|
25
|
+
update: function (html) {
|
26
|
+
this.clear();
|
27
|
+
this.content_holder.html(html);
|
28
|
+
this.bind();
|
29
|
+
this.spinner_off();
|
30
|
+
},
|
31
|
+
|
32
|
+
add: function () {
|
33
|
+
var that = this;
|
34
|
+
|
35
|
+
if (!this.processing) {
|
36
|
+
var selected_item = this.inactive_snippets.find('option:selected'),
|
37
|
+
selected_id = null,
|
38
|
+
values = [],
|
39
|
+
add_url = this.add_snippet.attr('href');
|
40
|
+
|
41
|
+
if (selected_item.length > 0 && selected_item.val() !== '') {
|
42
|
+
this.spinner_on();
|
43
|
+
|
44
|
+
add_url += '&add=' + selected_item.val();
|
45
|
+
|
46
|
+
$.ajax({
|
47
|
+
url: add_url,
|
48
|
+
type: 'GET',
|
49
|
+
dataType: 'html',
|
50
|
+
error: function (response) { alert(response); },
|
51
|
+
complete: function (e) {
|
52
|
+
// console.log(e);
|
53
|
+
},
|
54
|
+
success: function (response) {
|
55
|
+
|
56
|
+
that.update(response);
|
57
|
+
}
|
58
|
+
});
|
59
|
+
} else {
|
60
|
+
this.processing = false;
|
61
|
+
}
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
remove: function (elm) {
|
66
|
+
var that = this,
|
67
|
+
remove_url = $(elm).attr('href');
|
68
|
+
|
69
|
+
if (!this.processing) {
|
70
|
+
var values = [];
|
71
|
+
this.spinner_on();
|
72
|
+
|
73
|
+
// console.log('remove start');
|
74
|
+
$.ajax({
|
75
|
+
url: remove_url,
|
76
|
+
dataType: 'html',
|
77
|
+
error: function (response) {
|
78
|
+
alert(response);
|
79
|
+
},
|
80
|
+
complete: function (e) {
|
81
|
+
// console.log(e);
|
82
|
+
},
|
83
|
+
success: function (response) {
|
84
|
+
// console.log('pleas');
|
85
|
+
that.update(response);
|
86
|
+
}
|
87
|
+
});
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
/**
|
92
|
+
* Remove event handlers and other smells
|
93
|
+
*/
|
94
|
+
clear: function () {
|
95
|
+
// console.log('start clear');
|
96
|
+
this.content_holder.find('a').unbind('click');
|
97
|
+
this.add_snippet.unbind('click');
|
98
|
+
},
|
99
|
+
|
100
|
+
/**
|
101
|
+
* Bind event handlers and other smells ;-)
|
102
|
+
*/
|
103
|
+
bind: function () {
|
104
|
+
var that = this;
|
105
|
+
this.add_snippet = $('#add-snippet');
|
106
|
+
this.inactive_snippets = $('#inactive_snippets');
|
107
|
+
this.add_snippet.click(function (e) {
|
108
|
+
e.preventDefault();
|
109
|
+
that.add();
|
110
|
+
return false;
|
111
|
+
});
|
112
|
+
|
113
|
+
$('a.remove-snippet').click(function (e) {
|
114
|
+
e.preventDefault();
|
115
|
+
that.remove(this);
|
116
|
+
return false;
|
117
|
+
});
|
118
|
+
},
|
119
|
+
|
120
|
+
init: function () {
|
121
|
+
this.content_holder = $('#page_snippet_picker ');
|
122
|
+
if (this.content_holder.length > 0) {
|
123
|
+
this.bind();
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
|
128
|
+
PageSnippet.init();
|
129
|
+
});
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: refinerycms-snippets
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
|
9
|
+
- 1
|
10
|
+
version: 0.3.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Marek L.
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-05-
|
18
|
+
date: 2011-05-09 00:00:00 +02:00
|
18
19
|
default_executable:
|
19
20
|
dependencies: []
|
20
21
|
|
@@ -61,6 +62,7 @@ files:
|
|
61
62
|
- db/migrate/1_create_snippets.rb
|
62
63
|
- db/migrate/3_translate_snippets.rb
|
63
64
|
- db/seeds/snippets.rb
|
65
|
+
- public/javascripts/page-snippet-picker.js
|
64
66
|
has_rdoc: true
|
65
67
|
homepage:
|
66
68
|
licenses: []
|