humpyard 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +28 -0
- data/README.rdoc +61 -0
- data/VERSION +1 -0
- data/app/controllers/humpyard/assets_controller.rb +123 -0
- data/app/controllers/humpyard/elements_controller.rb +200 -0
- data/app/controllers/humpyard/errors_controller.rb +8 -0
- data/app/controllers/humpyard/pages_controller.rb +365 -0
- data/app/helpers/humpyard/pages_helper.rb +19 -0
- data/app/models/humpyard/asset.rb +22 -0
- data/app/models/humpyard/assets/paperclip_asset.rb +48 -0
- data/app/models/humpyard/assets/youtube_asset.rb +38 -0
- data/app/models/humpyard/element.rb +57 -0
- data/app/models/humpyard/elements/box_element.rb +15 -0
- data/app/models/humpyard/elements/media_element.rb +13 -0
- data/app/models/humpyard/elements/news_element.rb +13 -0
- data/app/models/humpyard/elements/sitemap_element.rb +11 -0
- data/app/models/humpyard/elements/text_element.rb +49 -0
- data/app/models/humpyard/news_item.rb +42 -0
- data/app/models/humpyard/page.rb +153 -0
- data/app/models/humpyard/pages/news_page.rb +71 -0
- data/app/models/humpyard/pages/static_page.rb +25 -0
- data/app/models/humpyard/pages/virtual_page.rb +30 -0
- data/app/views/humpyard/assets/_edit.html.haml +15 -0
- data/app/views/humpyard/assets/_index.html.haml +24 -0
- data/app/views/humpyard/assets/_list.html.haml +4 -0
- data/app/views/humpyard/assets/_list_item.html.haml +1 -0
- data/app/views/humpyard/assets/_show.html.haml +38 -0
- data/app/views/humpyard/assets/_show_asset.html.haml +3 -0
- data/app/views/humpyard/assets/destroy.js.erb +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/paperclip_assets/_info_table.html.haml +10 -0
- data/app/views/humpyard/assets/paperclip_assets/_show.html.haml +12 -0
- data/app/views/humpyard/assets/youtube_assets/_edit.html.haml +4 -0
- data/app/views/humpyard/assets/youtube_assets/_show.html.haml +5 -0
- data/app/views/humpyard/common/_head.html.haml +8 -0
- data/app/views/humpyard/common/_page_construct.html.haml +45 -0
- data/app/views/humpyard/elements/_edit.html.haml +25 -0
- data/app/views/humpyard/elements/_inline_edit.haml +0 -0
- data/app/views/humpyard/elements/_new.html.haml +1 -0
- data/app/views/humpyard/elements/_show.html.haml +29 -0
- data/app/views/humpyard/elements/_show_container.html.haml +3 -0
- data/app/views/humpyard/elements/_show_view.html.haml +2 -0
- data/app/views/humpyard/elements/box_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/box_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/box_elements/_show.html.haml +5 -0
- data/app/views/humpyard/elements/destroy.js.erb +1 -0
- data/app/views/humpyard/elements/error.js.erb +1 -0
- data/app/views/humpyard/elements/media_elements/_edit.html.haml +7 -0
- data/app/views/humpyard/elements/media_elements/_show.html.haml +8 -0
- data/app/views/humpyard/elements/news_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/news_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/news_elements/_show.html.haml +4 -0
- data/app/views/humpyard/elements/sitemap_elements/_edit.html.haml +5 -0
- data/app/views/humpyard/elements/sitemap_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/sitemap_elements/_show.html.haml +3 -0
- data/app/views/humpyard/elements/sitemap_elements/_show_part.html.haml +12 -0
- data/app/views/humpyard/elements/text_elements/_edit.html.haml +4 -0
- data/app/views/humpyard/elements/text_elements/_inline_edit.html.haml +0 -0
- data/app/views/humpyard/elements/text_elements/_show.html.haml +4 -0
- data/app/views/humpyard/pages/_content.html.haml +2 -0
- data/app/views/humpyard/pages/_edit.html.haml +39 -0
- data/app/views/humpyard/pages/_index.html.haml +23 -0
- data/app/views/humpyard/pages/_show.html.haml +16 -0
- data/app/views/humpyard/pages/_subtree.html.haml +6 -0
- data/app/views/humpyard/pages/_tree.html.haml +3 -0
- data/app/views/humpyard/pages/destroy.js.erb +4 -0
- data/app/views/humpyard/pages/news_pages/_detail.html.haml +10 -0
- data/app/views/humpyard/pages/news_pages/_edit.html.haml +3 -0
- data/app/views/humpyard/pages/news_pages/_show.html.haml +5 -0
- data/app/views/humpyard/pages/show.html.haml +3 -0
- data/app/views/humpyard/pages/static_pages/_edit.html.haml +1 -0
- data/app/views/humpyard/pages/static_pages/_show.html.haml +1 -0
- data/app/views/humpyard/pages/virtual_pages/_edit.html.haml +7 -0
- data/app/views/humpyard/pages/virtual_pages/_show.html.haml +4 -0
- data/app/views/humpyard/pages/welcome.html.haml +13 -0
- data/compass/stylesheets/_humpyard.scss +12 -0
- data/compass/stylesheets/humpyard/_backend.scss +1 -0
- data/compass/stylesheets/humpyard/_base.scss +144 -0
- data/compass/stylesheets/humpyard/_ie.scss +1 -0
- data/compass/stylesheets/humpyard/_jquery_ui_overrides.scss +380 -0
- data/compass/stylesheets/humpyard/_print.scss +3 -0
- data/config/locales/de.yml +84 -0
- data/config/locales/en.yml +81 -0
- data/config/routes.rb +38 -0
- data/db/migrate/20100321134138_base.rb +60 -0
- data/db/migrate/20100330204700_create_box_element.rb +24 -0
- data/db/migrate/20100401153655_page_template.rb +11 -0
- data/db/migrate/20100409195732_page_types.rb +26 -0
- data/db/migrate/20100413230623_element_yield.rb +14 -0
- data/db/migrate/20100415132312_news_page.rb +48 -0
- data/db/migrate/20100415193423_page_i18n_name.rb +27 -0
- data/db/migrate/20100415213700_create_news_element.rb +12 -0
- data/db/migrate/20100703120000_shared_elements.rb +9 -0
- data/db/migrate/20101001142534_page_modified_at.rb +11 -0
- data/db/migrate/20101003100138_create_sitemap_elements.rb +13 -0
- data/db/migrate/20101003122108_create_humpyard_pages_virtual_pages.rb +11 -0
- data/db/migrate/20101006070503_page_cache_control.rb +9 -0
- data/db/migrate/20101104173743_create_media.rb +36 -0
- data/db/migrate/20110425230524_media_with_link.rb +9 -0
- data/lib/generators/humpyard.rb +114 -0
- data/lib/generators/humpyard/auth/auth_generator.rb +191 -0
- data/lib/generators/humpyard/auth/templates/authlogic/README +9 -0
- data/lib/generators/humpyard/auth/templates/authlogic/controllers/user_sessions_controller.rb +22 -0
- data/lib/generators/humpyard/auth/templates/authlogic/migration.rb +17 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user.rb +7 -0
- data/lib/generators/humpyard/auth/templates/authlogic/models/user_session.rb +6 -0
- data/lib/generators/humpyard/auth/templates/authlogic/views/user_sessions/new.html.haml +12 -0
- data/lib/generators/humpyard/auth/templates/custom/README +8 -0
- data/lib/generators/humpyard/auth/templates/devise/README +14 -0
- data/lib/generators/humpyard/auth/templates/devise/models/ability.rb +14 -0
- data/lib/generators/humpyard/auth/templates/fake/README +0 -0
- data/lib/generators/humpyard/auth/templates/fake/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/README +16 -0
- data/lib/generators/humpyard/auth/templates/simple/config/humpyard_users.yml +2 -0
- data/lib/generators/humpyard/auth/templates/simple/controllers/user_sessions_controller.rb +39 -0
- data/lib/generators/humpyard/auth/templates/simple/models/ability.rb +12 -0
- data/lib/generators/humpyard/auth/templates/simple/views/user_sessions/new.html.haml +15 -0
- data/lib/generators/humpyard/element/USAGE +7 -0
- data/lib/generators/humpyard/element/element_generator.rb +82 -0
- data/lib/generators/humpyard/element/templates/_edit.html.haml +12 -0
- data/lib/generators/humpyard/element/templates/_inline_edit.html.haml +0 -0
- data/lib/generators/humpyard/element/templates/_show.html.haml +9 -0
- data/lib/generators/humpyard/element/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/element/templates/migration.rb +16 -0
- data/lib/generators/humpyard/element/templates/model.rb +11 -0
- data/lib/generators/humpyard/element/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/element/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/page/USAGE +7 -0
- data/lib/generators/humpyard/page/page_generator.rb +80 -0
- data/lib/generators/humpyard/page/templates/_edit.html.haml +7 -0
- data/lib/generators/humpyard/page/templates/_show.html.haml +4 -0
- data/lib/generators/humpyard/page/templates/fixtures.yml +23 -0
- data/lib/generators/humpyard/page/templates/migration.rb +16 -0
- data/lib/generators/humpyard/page/templates/model.rb +37 -0
- data/lib/generators/humpyard/page/templates/tests/rspec/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/shoulda/model.rb +7 -0
- data/lib/generators/humpyard/page/templates/tests/test_unit/model.rb +7 -0
- data/lib/generators/humpyard/skeleton/USAGE +6 -0
- data/lib/generators/humpyard/skeleton/skeleton_generator.rb +99 -0
- data/lib/generators/humpyard/skeleton/templates/compass.config +14 -0
- data/lib/generators/humpyard/skeleton/templates/images/ajax-loader.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/images/grid.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/compass.rb +16 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/haml.rb +3 -0
- data/lib/generators/humpyard/skeleton/templates/initializers/humpyard.rb +20 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/d.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/images/jstree/throbber.gif +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-1.5.1.js +8316 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-humpyard.js +790 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-rails.js +157 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery-ui-1.8.10.js +11544 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.form-2.64.js +803 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/javascripts/jquery.jstree.js +3510 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_222222_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_454545_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_888888_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/lib/generators/humpyard/skeleton/templates/javascripts/jquery-ui-18/stylesheets/smoothness/jquery-ui-1.8.10.css +573 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.sass +15 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/ie.scss +16 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.sass +12 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/partials/_base.scss +11 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.sass +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/print.scss +3 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.sass +78 -0
- data/lib/generators/humpyard/skeleton/templates/stylesheets/screen.scss +90 -0
- data/lib/generators/humpyard/skeleton/templates/views/layout.html.haml +28 -0
- data/lib/html_to_textile.rb +220 -0
- data/lib/humpyard.rb +70 -0
- data/lib/humpyard/action_controller/base.rb +24 -0
- data/lib/humpyard/active_model/naming.rb +29 -0
- data/lib/humpyard/active_model/translation.rb +26 -0
- data/lib/humpyard/active_model/validators/publish_range.rb +14 -0
- data/lib/humpyard/active_record/acts/asset.rb +68 -0
- data/lib/humpyard/active_record/acts/container_element.rb +26 -0
- data/lib/humpyard/active_record/acts/element.rb +89 -0
- data/lib/humpyard/active_record/acts/page.rb +101 -0
- data/lib/humpyard/active_record/has/title_for_url.rb +75 -0
- data/lib/humpyard/compass.rb +6 -0
- data/lib/humpyard/config.rb +235 -0
- data/lib/humpyard/engine.rb +7 -0
- data/lib/humpyard/uri_parser.rb +16 -0
- data/lib/humpyard/uri_parser/assets_uri_parser.rb +15 -0
- data/lib/humpyard/uri_parser/pages_uri_parser.rb +15 -0
- data/lib/tasks/humpyard.rake +103 -0
- metadata +331 -0
@@ -0,0 +1,790 @@
|
|
1
|
+
// Humpyard actions
|
2
|
+
;jQuery.humpyard || (function($) {
|
3
|
+
$.humpyard = {
|
4
|
+
dialog_count: 0,
|
5
|
+
|
6
|
+
ajax_dialog_commands: {
|
7
|
+
dialog: function(dialog, form, options) {
|
8
|
+
dialog.dialog('close');
|
9
|
+
},
|
10
|
+
replace: function(dialog, form, options) {
|
11
|
+
$.each(options, function(i,k){
|
12
|
+
var elem = $('#' + k['element']);
|
13
|
+
if(k['content']) {
|
14
|
+
elem.html(k['content']);
|
15
|
+
$.humpyard.initTreeView(elem);
|
16
|
+
}
|
17
|
+
if(k['url']) {
|
18
|
+
elem.load(k['url'], function(r, s, x) {
|
19
|
+
$.humpyard.initElements(elem);
|
20
|
+
elem.effect("highlight", {}, 2000);
|
21
|
+
});
|
22
|
+
}
|
23
|
+
});
|
24
|
+
},
|
25
|
+
insert: function(dialog, form, options) {
|
26
|
+
$.each(options, function(i,k){
|
27
|
+
var elem = $('<div></div>');
|
28
|
+
if(k['before']) {
|
29
|
+
elem.insertBefore($('#'+k['before']));
|
30
|
+
} else if(k['after']) {
|
31
|
+
elem.insertAfter($('#'+k['after']));
|
32
|
+
} else {
|
33
|
+
elem.appendTo($('#'+k['parent']+' div[data-droppable]:first'));
|
34
|
+
}
|
35
|
+
elem.load(k['url'], function(r, s, x) {
|
36
|
+
children = elem.children();
|
37
|
+
children.insertBefore(elem);
|
38
|
+
elem.remove();
|
39
|
+
$.humpyard.initElements(children);
|
40
|
+
children.effect("highlight", {}, 2000);
|
41
|
+
});
|
42
|
+
});
|
43
|
+
},
|
44
|
+
remove: function(dialog, form, options) {
|
45
|
+
$.each(options, function(i,k){
|
46
|
+
var elem = $('#' + k['element']);
|
47
|
+
elem.remove();
|
48
|
+
});
|
49
|
+
},
|
50
|
+
errors: function(dialog, form, options) {
|
51
|
+
$.each(options, function(attr, errors) {
|
52
|
+
errors = $.isArray(errors) ? errors : [errors];
|
53
|
+
$('.input.attr_' + attr + ' .field-highlight', form).addClass("ui-state-error");
|
54
|
+
field_errors = $('.input.attr_' + attr + ' .field-errors', form);
|
55
|
+
field_errors.append(errors.join(', '));
|
56
|
+
field_errors.fadeIn();
|
57
|
+
});
|
58
|
+
},
|
59
|
+
flash: function(dialog, form, options) {
|
60
|
+
var f = $('<div class="flash">xxx</div>').html(options['content']).addClass(options['level']).hide();
|
61
|
+
if($('.flashes', form).size() > 0) {
|
62
|
+
$('.flashes', form).append(f)
|
63
|
+
} else {
|
64
|
+
$(form).prepend(f);
|
65
|
+
}
|
66
|
+
f.show('blind',300).delay(1800).hide('blind',300);
|
67
|
+
}
|
68
|
+
},
|
69
|
+
|
70
|
+
initEditButtons: function(elems) {
|
71
|
+
elems.each(function(idx, el){
|
72
|
+
var icon = $(el).attr('data-icon');
|
73
|
+
if (icon) {
|
74
|
+
$(el).button({text:false, icons: {primary:icon}});
|
75
|
+
} else {
|
76
|
+
$(el).button();
|
77
|
+
}
|
78
|
+
});
|
79
|
+
},
|
80
|
+
|
81
|
+
initSortables: function(elem, name, options) {
|
82
|
+
//$('div[data-sortable=' + name+ ']', elem).css('min-height','20px');
|
83
|
+
$('div[data-sortable=' + name+ ']', elem).addClass('droparea');
|
84
|
+
|
85
|
+
params = {
|
86
|
+
items: '> div[data-draggable=' + name+ ']',
|
87
|
+
|
88
|
+
connectWith: 'div[data-sortable=' + name+ ']',
|
89
|
+
placeholder: 'ui-state-highlight',
|
90
|
+
update: function(e, ui) {
|
91
|
+
var item = ui.item;
|
92
|
+
|
93
|
+
var sortable = item.parents('div[data-sortable=' + name+ ']:first');;
|
94
|
+
var parent = item.parents('div[data-draggable=' + name+ ']:first');
|
95
|
+
var prev = item.prev('div[data-draggable=' + name+ ']');
|
96
|
+
var next = item.next('div[data-draggable=' + name+ ']');
|
97
|
+
|
98
|
+
if(options.update) {
|
99
|
+
options.update(sortable, item, parent, prev, next);
|
100
|
+
}
|
101
|
+
}
|
102
|
+
};
|
103
|
+
|
104
|
+
if(options.handle) params.handle = options.handle;
|
105
|
+
|
106
|
+
$('div[data-sortable=' + name+ ']', elem).sortable(params);
|
107
|
+
},
|
108
|
+
|
109
|
+
tokenized_post: function(url, params) {
|
110
|
+
var csrf_token = $('meta[name=csrf-token]').attr('content'),
|
111
|
+
csrf_param = $('meta[name=csrf-param]').attr('content');
|
112
|
+
|
113
|
+
params[csrf_param] = csrf_token;
|
114
|
+
console.log("param: " + csrf_param);
|
115
|
+
console.log("token: " + params[csrf_param]);
|
116
|
+
|
117
|
+
$.post(url, params)
|
118
|
+
},
|
119
|
+
|
120
|
+
initPages: function(elem) {
|
121
|
+
$.humpyard.initSortables(elem, 'hy-pages', {
|
122
|
+
update: function(sortable, item, parent, prev, next) {
|
123
|
+
var params = {
|
124
|
+
id: item.attr('data-page-id'),
|
125
|
+
parent_id: parent.attr('data-page-id'),
|
126
|
+
prev_id: prev.attr('data-page-id'),
|
127
|
+
next_id: next.attr('data-page-id')
|
128
|
+
};
|
129
|
+
|
130
|
+
if(item.attr('data-page-type')) {
|
131
|
+
params['type'] = item.attr('data-page-type');
|
132
|
+
|
133
|
+
$.humpyard.dialog(item.attr('data-create-url'), {
|
134
|
+
get: params,
|
135
|
+
width: '600px',
|
136
|
+
modal: true
|
137
|
+
});
|
138
|
+
item.empty();
|
139
|
+
} else {
|
140
|
+
$.humpyard.tokenized_post(sortable.attr('data-sortable-update-url'), params);
|
141
|
+
}
|
142
|
+
}
|
143
|
+
});
|
144
|
+
},
|
145
|
+
|
146
|
+
initElements: function(elem) {
|
147
|
+
$.humpyard.initSortables(elem, 'hy-elements', {
|
148
|
+
handle: 'a[data-draghandle]',
|
149
|
+
update: function(sortable, item, parent, prev, next) {
|
150
|
+
var params = {
|
151
|
+
id: item.attr('data-element-id'),
|
152
|
+
page_id: $('#hy-body').attr('data-page-id'),
|
153
|
+
yield_name: item.parents('.hy-content:first').attr('data-content-yield'),
|
154
|
+
container_id: parent.attr('data-element-id'),
|
155
|
+
prev_id: prev.attr('data-element-id'),
|
156
|
+
next_id: next.attr('data-element-id')
|
157
|
+
};
|
158
|
+
|
159
|
+
if(item.attr('data-element-type')) {
|
160
|
+
params['type'] = item.attr('data-element-type');
|
161
|
+
|
162
|
+
$.humpyard.dialog(item.attr('data-create-url'), {
|
163
|
+
get: params,
|
164
|
+
width: '600px',
|
165
|
+
modal: true
|
166
|
+
});
|
167
|
+
item.empty();
|
168
|
+
} else {
|
169
|
+
$.humpyard.tokenized_post(sortable.attr('data-sortable-update-url'), params);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
});
|
173
|
+
$.humpyard.initEditButtons($('.hy-el-menu a', elem));
|
174
|
+
},
|
175
|
+
|
176
|
+
initForm: function(elem) {
|
177
|
+
function detect_native(type) {
|
178
|
+
var i = document.createElement("input");
|
179
|
+
i.setAttribute("type", type);
|
180
|
+
return i.type !== "text";
|
181
|
+
}
|
182
|
+
|
183
|
+
// configure date pickers
|
184
|
+
if(!detect_native('date')) {
|
185
|
+
$('input[data-type=date]', elem).datepicker({
|
186
|
+
showButtonPanel: true,
|
187
|
+
changeMonth: true,
|
188
|
+
changeYear: true,
|
189
|
+
dateFormat: 'yy-mm-dd'
|
190
|
+
});
|
191
|
+
}
|
192
|
+
if(!detect_native('datetime')) {
|
193
|
+
$('input[data-type=datetime]', elem).datepicker({
|
194
|
+
showButtonPanel: true,
|
195
|
+
changeMonth: true,
|
196
|
+
changeYear: true,
|
197
|
+
dateFormat: 'yy-mm-dd'
|
198
|
+
});
|
199
|
+
}
|
200
|
+
},
|
201
|
+
|
202
|
+
initTabView: function(container) {
|
203
|
+
var tabview = $('.humpyard-tabview', container);
|
204
|
+
var tab_sources = $('.humpyard-tab', tabview);
|
205
|
+
var tabs = $('<ul></ul>').prependTo(tabview);
|
206
|
+
var tabcount=0;
|
207
|
+
|
208
|
+
tab_sources.each(function(i,k){
|
209
|
+
tabcount++;
|
210
|
+
id = 'humpyard-' + $.humpyard.dialog_count + '-tab-' + tabcount;
|
211
|
+
$(k).attr('id', id)
|
212
|
+
$('<li><a href="#' +id+ '">' + $('.humpyard-tab-title',k).html() + '</a></li>').append().appendTo(tabs);
|
213
|
+
$('.humpyard-tab-title',k).remove();
|
214
|
+
})
|
215
|
+
|
216
|
+
if(tabcount > 0) {
|
217
|
+
tabview.tabs();
|
218
|
+
}
|
219
|
+
},
|
220
|
+
|
221
|
+
initTreeView: function(container) {
|
222
|
+
var treeview = $('.humpyard-treeview', container);
|
223
|
+
treeview.bind("loaded.jstree", function (event, data) {
|
224
|
+
treeview.jstree("open_all");
|
225
|
+
// TODO: select current page in the tree
|
226
|
+
//treeview.select_node()...
|
227
|
+
})
|
228
|
+
|
229
|
+
.bind("move_node.jstree", function(event, data) {
|
230
|
+
var item = data.rslt.o;
|
231
|
+
var parent = data.rslt.np;
|
232
|
+
var previous = null;
|
233
|
+
var next = null;
|
234
|
+
|
235
|
+
switch(data.rslt.p) {
|
236
|
+
case "before":
|
237
|
+
next = data.rslt.o.next();
|
238
|
+
previous = data.rslt.o.prev();
|
239
|
+
break;
|
240
|
+
case "after" :
|
241
|
+
previous = data.rslt.o.prev()
|
242
|
+
next = data.rslt.o.next();
|
243
|
+
break;
|
244
|
+
case "inside":
|
245
|
+
case "first" :
|
246
|
+
case "last":
|
247
|
+
break;
|
248
|
+
default:
|
249
|
+
alert("position not handled: " + data.rslt.p + " " + data.rslt.r.attr("id"));
|
250
|
+
return;
|
251
|
+
}
|
252
|
+
|
253
|
+
var params = {
|
254
|
+
id: item.attr('data-page-id'),
|
255
|
+
parent_id: parent ? parent.attr('data-page-id') : undefined,
|
256
|
+
prev_id: previous ? previous.attr('data-page-id') : undefined,
|
257
|
+
next_id: next ? next.attr('data-page-id') : undefined
|
258
|
+
};
|
259
|
+
|
260
|
+
$.humpyard.tokenized_post(treeview.attr('data-sortable-update-url'), params);
|
261
|
+
})
|
262
|
+
|
263
|
+
.jstree({
|
264
|
+
"core" : {
|
265
|
+
"html_titles": true,
|
266
|
+
"animation": 100
|
267
|
+
},
|
268
|
+
"dnd" : {
|
269
|
+
//"drop_target" : true,
|
270
|
+
//"drag_target" : true,
|
271
|
+
"drop_finish" : function(data) {
|
272
|
+
// console.log("drop_finish");
|
273
|
+
// console.log(data);
|
274
|
+
},
|
275
|
+
"drag_check" : function (data) {
|
276
|
+
// check root node - no dnd
|
277
|
+
// console.log("DRAGCHECK");
|
278
|
+
return {
|
279
|
+
after : true,
|
280
|
+
before : true,
|
281
|
+
inside : true
|
282
|
+
};
|
283
|
+
},
|
284
|
+
"drag_finish" : function () {
|
285
|
+
alert("DRAG OK");
|
286
|
+
}
|
287
|
+
},
|
288
|
+
"themes" : {
|
289
|
+
"theme" : "default",
|
290
|
+
"dots" : true,
|
291
|
+
"icons" : true,
|
292
|
+
"url": "/stylesheets/jstree/style.css"
|
293
|
+
},
|
294
|
+
"ui" : {
|
295
|
+
"select_limit": 1
|
296
|
+
},
|
297
|
+
"plugins" : [
|
298
|
+
"themes",
|
299
|
+
"html_data",
|
300
|
+
"crrm",
|
301
|
+
"dnd",
|
302
|
+
"ui"
|
303
|
+
]
|
304
|
+
});
|
305
|
+
|
306
|
+
},
|
307
|
+
|
308
|
+
submitForm: function(form, dialog, targetForm) {
|
309
|
+
if(typeof(targetForm) == 'undefined') {
|
310
|
+
targetForm = form
|
311
|
+
}
|
312
|
+
var options = {
|
313
|
+
dataType: 'json',
|
314
|
+
complete: function(xhr, status) {
|
315
|
+
result = jQuery.parseJSON(xhr.responseText);
|
316
|
+
// reset error messages
|
317
|
+
$('.field-highlight', form).removeClass("ui-state-error");
|
318
|
+
$('.field-errors', form).empty().hide();
|
319
|
+
// execute commands given by ajax call
|
320
|
+
$.each(result, function(attr, options) {
|
321
|
+
if($.humpyard.ajax_dialog_commands[attr]) {
|
322
|
+
$.humpyard.ajax_dialog_commands[attr](dialog, targetForm, options);
|
323
|
+
}
|
324
|
+
});
|
325
|
+
}
|
326
|
+
}
|
327
|
+
|
328
|
+
if(form.find('input[type=file]').length > 0 || form.attr("enctype") == "multipart/form-data") {
|
329
|
+
options['data'] = { ul_quirk: 'true' };
|
330
|
+
options['iframe'] = true
|
331
|
+
}
|
332
|
+
|
333
|
+
if(form.trigger('humpyard:form:submit')) {
|
334
|
+
form.ajaxSubmit(options);
|
335
|
+
}
|
336
|
+
},
|
337
|
+
|
338
|
+
dialogLink: function(link, dialog) {
|
339
|
+
var url = '' + link.attr('href');
|
340
|
+
var options = {
|
341
|
+
url: url,
|
342
|
+
dataType: 'json',
|
343
|
+
complete: function(xhr, status) {
|
344
|
+
result = jQuery.parseJSON(xhr.responseText);
|
345
|
+
// execute commands given by ajax call
|
346
|
+
$.each(result, function(attr, options) {
|
347
|
+
if($.humpyard.ajax_dialog_commands[attr]) {
|
348
|
+
$.humpyard.ajax_dialog_commands[attr](dialog, null, options);
|
349
|
+
}
|
350
|
+
});
|
351
|
+
}
|
352
|
+
};
|
353
|
+
|
354
|
+
if(link.trigger('humpyard:link:click')) {
|
355
|
+
$.ajax(options);
|
356
|
+
}
|
357
|
+
},
|
358
|
+
|
359
|
+
dialog: function(url, options) {
|
360
|
+
options = options || {};
|
361
|
+
var post_options = options['post'] || null;
|
362
|
+
var get_options = $.param(options['get'] || {});
|
363
|
+
var dialog_id = options['dialog_id'];
|
364
|
+
var dialog = null;
|
365
|
+
options['close'] = options['close'] || function(ev, ui) { $(this).remove(); };
|
366
|
+
|
367
|
+
// Remove get and post from options for dialog
|
368
|
+
/*
|
369
|
+
if(options['get']) {
|
370
|
+
options.splice('get');
|
371
|
+
}
|
372
|
+
if(options['post']) {
|
373
|
+
options.splice('post');
|
374
|
+
}
|
375
|
+
*/
|
376
|
+
options['get'] = null;
|
377
|
+
options['post'] = null;
|
378
|
+
options['dialog_id'] = null;
|
379
|
+
|
380
|
+
if(dialog_id) {
|
381
|
+
if($('#' + dialog_id).size()) {
|
382
|
+
dialog = $('#' + dialog_id);
|
383
|
+
dialog.dialog("moveToTop");
|
384
|
+
return;
|
385
|
+
} else {
|
386
|
+
dialog = $('<div id="' + dialog_id + '"></div>').appendTo('body').dialog(options);
|
387
|
+
}
|
388
|
+
} else {
|
389
|
+
dialog = $('<div></div>').appendTo('body').dialog(options);
|
390
|
+
}
|
391
|
+
|
392
|
+
dialog.load(url+(get_options ? '?'+get_options : ''), post_options, function(response, status, xhr) {
|
393
|
+
if (status == "error") {
|
394
|
+
var error_content = '<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>Sorry, an error occurred:</strong> '+xhr.statusText+' ['+xhr.status+']</p></div>';
|
395
|
+
dialog.dialog({
|
396
|
+
title: 'An Error occured',
|
397
|
+
dialogClass: 'alert',
|
398
|
+
buttons: {
|
399
|
+
'Ok': function() {
|
400
|
+
$(this).dialog('close');
|
401
|
+
}
|
402
|
+
}
|
403
|
+
});
|
404
|
+
dialog.html(error_content);
|
405
|
+
} else {
|
406
|
+
dialog.dialog({
|
407
|
+
title: $('.humpyard-dialog-title', dialog).html()
|
408
|
+
});
|
409
|
+
$('.humpyard-dialog-title', dialog).remove();
|
410
|
+
|
411
|
+
$.humpyard.initForm(dialog);
|
412
|
+
$.humpyard.initPages(dialog);
|
413
|
+
$.humpyard.initTabView(dialog);
|
414
|
+
$.humpyard.initTreeView(dialog);
|
415
|
+
$.humpyard.initEditButtons($('.humpyard-form-buttons a, .humpyard-form-buttons button', dialog));
|
416
|
+
|
417
|
+
|
418
|
+
// Add buttons
|
419
|
+
|
420
|
+
buttons = {};
|
421
|
+
if($('form[data-dialog-form]:first', $(this)).size()) {
|
422
|
+
buttons = {};
|
423
|
+
buttons['Ok'] = function() {
|
424
|
+
var form = $('form[data-dialog-form]:first', $(this));
|
425
|
+
$.humpyard.submitForm(form, dialog);
|
426
|
+
};
|
427
|
+
buttons['Cancel'] = function() {
|
428
|
+
$(this).dialog('close');
|
429
|
+
}
|
430
|
+
} else {
|
431
|
+
buttons = false;
|
432
|
+
}
|
433
|
+
|
434
|
+
$('.humpyard-dialog-buttons').each(function(i,k){
|
435
|
+
dialog.dialog({
|
436
|
+
buttons: buttons
|
437
|
+
});
|
438
|
+
});
|
439
|
+
|
440
|
+
$('.humpyard-dialog-buttons').remove();
|
441
|
+
|
442
|
+
// run optional dialog functionality
|
443
|
+
if(options['load']) {
|
444
|
+
options['load'](dialog);
|
445
|
+
}
|
446
|
+
|
447
|
+
$.humpyard.dialog_count++;
|
448
|
+
}
|
449
|
+
});
|
450
|
+
},
|
451
|
+
|
452
|
+
endOfClass: true
|
453
|
+
}
|
454
|
+
})(jQuery);
|
455
|
+
|
456
|
+
// Humpyard actions / UJS
|
457
|
+
jQuery(function($) {
|
458
|
+
var csrf_token = $('meta[name=csrf-token]').attr('content'),
|
459
|
+
csrf_param = $('meta[name=csrf-param]').attr('content');
|
460
|
+
|
461
|
+
// bind ajax indicator to ajax events
|
462
|
+
$(document).ajaxSend(function() {
|
463
|
+
$(".ajax-indicator").addClass("active");
|
464
|
+
}).ajaxStop(function() {
|
465
|
+
$(".ajax-indicator").removeClass("active");
|
466
|
+
});
|
467
|
+
|
468
|
+
// Dialog UJS
|
469
|
+
$('a[data-dialog]').live('click', function (e) {
|
470
|
+
var options = {};
|
471
|
+
var url = $(this).attr('href');
|
472
|
+
|
473
|
+
$.each($(this).attr('data-dialog').split(';'), function(i){
|
474
|
+
attr = this.split(':');
|
475
|
+
switch(attr[0]) {
|
476
|
+
case 'modal':
|
477
|
+
case 'dialog_id':
|
478
|
+
options[attr[0]] = attr[1];
|
479
|
+
break;
|
480
|
+
case 'size':
|
481
|
+
size = attr[1].split('x');
|
482
|
+
options['width'] = parseInt(size[0]);
|
483
|
+
if(size[1]) {
|
484
|
+
options['height'] = parseInt(size[1]);
|
485
|
+
}
|
486
|
+
break;
|
487
|
+
}
|
488
|
+
})
|
489
|
+
|
490
|
+
$.humpyard.dialog(url, options);
|
491
|
+
e.preventDefault();
|
492
|
+
});
|
493
|
+
|
494
|
+
// Init Humpyard UI
|
495
|
+
$.humpyard.initEditButtons($('#hy-top a'));
|
496
|
+
$.humpyard.initElements($('#hy-body'));
|
497
|
+
|
498
|
+
// copied and modified the start, stop and drag from ui.draggable to this call
|
499
|
+
$('div[data-addable]').draggable({
|
500
|
+
helper: 'clone',
|
501
|
+
revert: 'invalid',
|
502
|
+
start: function(event, ui) {
|
503
|
+
var inst = $(this).data("draggable"), uiSortable = $.extend({}, ui, { item: inst.element });
|
504
|
+
inst.sortables = [];
|
505
|
+
$('div[data-droppable=' + $(this).attr('data-draggable') + ']').each(function() {
|
506
|
+
var sortable = $.data(this, 'sortable');
|
507
|
+
if (sortable && !sortable.options.disabled) {
|
508
|
+
inst.sortables.push({
|
509
|
+
instance: sortable,
|
510
|
+
shouldRevert: sortable.options.revert
|
511
|
+
});
|
512
|
+
sortable._refreshItems(); //Do a one-time refresh at start to refresh the containerCache
|
513
|
+
sortable._trigger("activate", event, uiSortable);
|
514
|
+
}
|
515
|
+
});
|
516
|
+
},
|
517
|
+
stop: function(event, ui) {
|
518
|
+
//If we are still over the sortable, we fake the stop event of the sortable, but also remove helper
|
519
|
+
var inst = $(this).data("draggable"),
|
520
|
+
uiSortable = $.extend({}, ui, { item: inst.element });
|
521
|
+
|
522
|
+
$.each(inst.sortables, function() {
|
523
|
+
if(this.instance.isOver) {
|
524
|
+
this.instance.isOver = 0;
|
525
|
+
|
526
|
+
inst.cancelHelperRemoval = true; //Don't remove the helper in the draggable instance
|
527
|
+
this.instance.cancelHelperRemoval = false; //Remove it in the sortable instance (so sortable plugins like revert still work)
|
528
|
+
|
529
|
+
//The sortable revert is supported, and we have to set a temporary dropped variable on the draggable to support revert: 'valid/invalid'
|
530
|
+
if(this.shouldRevert) this.instance.options.revert = true;
|
531
|
+
|
532
|
+
//Trigger the stop of the sortable
|
533
|
+
this.instance._mouseStop(event);
|
534
|
+
|
535
|
+
this.instance.options.helper = this.instance.options._helper;
|
536
|
+
|
537
|
+
//If the helper has been the original item, restore properties in the sortable
|
538
|
+
if(inst.options.helper == 'original')
|
539
|
+
this.instance.currentItem.css({ top: 'auto', left: 'auto' });
|
540
|
+
} else {
|
541
|
+
this.instance.cancelHelperRemoval = false; //Remove the helper in the sortable instance
|
542
|
+
this.instance._trigger("deactivate", event, uiSortable);
|
543
|
+
}
|
544
|
+
});
|
545
|
+
},
|
546
|
+
drag: function(event, ui) {
|
547
|
+
var inst = $(this).data("draggable"), self = this;
|
548
|
+
var checkPos = function(o) {
|
549
|
+
var dyClick = this.offset.click.top, dxClick = this.offset.click.left;
|
550
|
+
var helperTop = this.positionAbs.top, helperLeft = this.positionAbs.left;
|
551
|
+
var itemHeight = o.height, itemWidth = o.width;
|
552
|
+
var itemTop = o.top, itemLeft = o.left;
|
553
|
+
|
554
|
+
return $.ui.isOver(helperTop + dyClick, helperLeft + dxClick, itemTop, itemLeft, itemHeight, itemWidth);
|
555
|
+
};
|
556
|
+
|
557
|
+
var dragIn = function(draggable) {
|
558
|
+
//If it intersects, we use a little isOver variable and set it once, so our move-in stuff gets fired only once
|
559
|
+
if(!draggable.instance.isOver) {
|
560
|
+
draggable.instance.isOver = 1;
|
561
|
+
//Now we fake the start of dragging for the sortable instance,
|
562
|
+
//by cloning the list group item, appending it to the sortable and using it as inst.currentItem
|
563
|
+
//We can then fire the start event of the sortable with our passed browser event, and our own helper (so it doesn't create a new one)
|
564
|
+
draggable.instance.currentItem = $(self).clone().appendTo(draggable.instance.element).data("sortable-item", true);
|
565
|
+
draggable.instance.options._helper = draggable.instance.options.helper; //Store helper option to later restore it
|
566
|
+
draggable.instance.options.helper = function() { return ui.helper[0]; };
|
567
|
+
|
568
|
+
event.target = draggable.instance.currentItem[0];
|
569
|
+
draggable.instance._mouseCapture(event, true);
|
570
|
+
draggable.instance._mouseStart(event, true, true);
|
571
|
+
|
572
|
+
//Because the browser event is way off the new appended portlet, we modify a couple of variables to reflect the changes
|
573
|
+
draggable.instance.offset.click.top = inst.offset.click.top;
|
574
|
+
draggable.instance.offset.click.left = inst.offset.click.left;
|
575
|
+
draggable.instance.offset.parent.left -= inst.offset.parent.left - draggable.instance.offset.parent.left;
|
576
|
+
draggable.instance.offset.parent.top -= inst.offset.parent.top - draggable.instance.offset.parent.top;
|
577
|
+
|
578
|
+
inst._trigger("toSortable", event);
|
579
|
+
inst.dropped = draggable.instance.element; //draggable revert needs that
|
580
|
+
//hack so receive/update callbacks work (mostly)
|
581
|
+
inst.currentItem = inst.element;
|
582
|
+
draggable.instance.fromOutside = inst;
|
583
|
+
}
|
584
|
+
//Provided we did all the previous steps, we can fire the drag event of the sortable on every draggable drag, when it intersects with the sortable
|
585
|
+
if(draggable.instance.currentItem) draggable.instance._mouseDrag(event);
|
586
|
+
}
|
587
|
+
|
588
|
+
var dragOut = function(draggable) {
|
589
|
+
//If it doesn't intersect with the sortable, and it intersected before,
|
590
|
+
//we fake the drag stop of the sortable, but make sure it doesn't remove the helper by using cancelHelperRemoval
|
591
|
+
if(draggable.instance.isOver) {
|
592
|
+
draggable.instance.isOver = 0;
|
593
|
+
draggable.instance.cancelHelperRemoval = true;
|
594
|
+
|
595
|
+
//Prevent reverting on draggable forced stop
|
596
|
+
draggable.instance.options.revert = false;
|
597
|
+
|
598
|
+
// The out event needs to be triggered independently
|
599
|
+
draggable.instance._trigger('out', event, draggable.instance._uiHash(draggable.instance));
|
600
|
+
|
601
|
+
draggable.instance._mouseStop(event, true);
|
602
|
+
draggable.instance.options.helper = draggable.instance.options._helper;
|
603
|
+
|
604
|
+
//Now we remove our currentItem, the list group clone again, and the placeholder, and animate the helper back to it's original size
|
605
|
+
draggable.instance.currentItem.remove();
|
606
|
+
if(draggable.instance.placeholder) draggable.instance.placeholder.remove();
|
607
|
+
|
608
|
+
inst._trigger("fromSortable", event);
|
609
|
+
inst.dropped = false; //draggable revert needs that
|
610
|
+
}
|
611
|
+
}
|
612
|
+
|
613
|
+
var intersections = [];
|
614
|
+
|
615
|
+
$.each(inst.sortables, function(i) {
|
616
|
+
// console.log(this);
|
617
|
+
|
618
|
+
//Copy over some variables to allow calling the sortable's native _intersectsWith
|
619
|
+
this.instance.positionAbs = inst.positionAbs;
|
620
|
+
this.instance.helperProportions = inst.helperProportions;
|
621
|
+
this.instance.offset.click = inst.offset.click;
|
622
|
+
|
623
|
+
// Collect all intersections
|
624
|
+
if(this.instance._intersectsWith(this.instance.containerCache)) {
|
625
|
+
intersections.push(this.instance);
|
626
|
+
};
|
627
|
+
});
|
628
|
+
|
629
|
+
// Find top most intersection
|
630
|
+
var topIntersection = intersections.pop();
|
631
|
+
while(actual = intersections.pop()) {
|
632
|
+
if($.inArray(actual.element, $('div[data-droppable]', topIntersection.element))) {
|
633
|
+
topIntersection = actual;
|
634
|
+
}
|
635
|
+
}
|
636
|
+
|
637
|
+
// Handle drag in and out of intersections
|
638
|
+
$.each(inst.sortables, function(i) {
|
639
|
+
if(this.instance == topIntersection) {
|
640
|
+
// console.log('drag in');
|
641
|
+
dragIn(this);
|
642
|
+
} else {
|
643
|
+
// console.log('drag out');
|
644
|
+
dragOut(this);
|
645
|
+
}
|
646
|
+
});
|
647
|
+
}
|
648
|
+
});
|
649
|
+
|
650
|
+
/*
|
651
|
+
// Simple Method not working with nested elements
|
652
|
+
$('div[data-addable]').draggable({
|
653
|
+
connectToSortable: 'div[data-droppable]',
|
654
|
+
helper: 'clone',
|
655
|
+
revert: 'invalid'
|
656
|
+
});
|
657
|
+
*/
|
658
|
+
|
659
|
+
// Humpyard elements menu
|
660
|
+
|
661
|
+
$('.hy-el').live('mouseover', function(){
|
662
|
+
var el = $(this);
|
663
|
+
$('.hy-el').removeClass('hy-el-active');
|
664
|
+
el.addClass('hy-el-active');
|
665
|
+
$('.hy-el-menu', el).position({
|
666
|
+
my: 'left top',
|
667
|
+
at: 'left top',
|
668
|
+
of: el,
|
669
|
+
offset: "2 2"
|
670
|
+
});
|
671
|
+
$('.hy-marker-frame.top', el).position({ my: 'left top', at: 'left top', of: el }).width(el.width()).height(1);
|
672
|
+
$('.hy-marker-frame.bottom', el).position({ my: 'left bottom', at: 'left bottom', of: el }).width(el.width()).height(1);
|
673
|
+
$('.hy-marker-frame.left', el).position({ my: 'left top', at: 'left top', of: el }).width(1).height(el.height());
|
674
|
+
$('.hy-marker-frame.right', el).position({ my: 'right top', at: 'right top', of: el }).width(1).height(el.height());
|
675
|
+
}).live('mouseout', function(){
|
676
|
+
$('.hy-el').removeClass('hy-el-active');
|
677
|
+
});
|
678
|
+
|
679
|
+
$('a[data-draghandle]').live('click',function(e){
|
680
|
+
e.preventDefault();
|
681
|
+
});
|
682
|
+
|
683
|
+
// dialog left column links
|
684
|
+
$('div[data-dialog-link] a, a[data-dialog-link]').live('click', function(e){
|
685
|
+
var columns = $(this).parents('.dialog-columns:first');
|
686
|
+
var content = columns.children('.right-dialog-column');
|
687
|
+
$('a', columns).removeClass('active');
|
688
|
+
$(this).addClass('active');
|
689
|
+
content.empty().load($(this).attr('href'), function(response, status, xhr) {
|
690
|
+
dialog = columns.parents('.ui-dialog-content:first');
|
691
|
+
if (status == "error") {
|
692
|
+
var error_content = '<div class="ui-state-error ui-corner-all" style="padding: 0 .7em;"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span><strong>Sorry, an error occurred:</strong> '+xhr.statusText+' ['+xhr.status+']</p></div>';
|
693
|
+
dialog.dialog({
|
694
|
+
title: 'An Error occured',
|
695
|
+
dialogClass: 'alert',
|
696
|
+
buttons: {
|
697
|
+
'Ok': function() {
|
698
|
+
$(this).dialog('close');
|
699
|
+
}
|
700
|
+
}
|
701
|
+
});
|
702
|
+
dialog.html(error_content);
|
703
|
+
} else {
|
704
|
+
dialog.dialog({
|
705
|
+
title: $('.humpyard-dialog-title', content).html()
|
706
|
+
});
|
707
|
+
$('.humpyard-dialog-title', content).remove();
|
708
|
+
|
709
|
+
$.humpyard.initForm(content);
|
710
|
+
$.humpyard.initTabView(content);
|
711
|
+
$.humpyard.initEditButtons($('.humpyard-form-buttons a, .humpyard-form-buttons button', content));
|
712
|
+
|
713
|
+
}
|
714
|
+
});
|
715
|
+
e.preventDefault();
|
716
|
+
});
|
717
|
+
|
718
|
+
// Links to commands UJS
|
719
|
+
commands = {
|
720
|
+
toggleEditMode: function(link) {
|
721
|
+
$('.hy-eb').toggleClass('hy-edit-active', 250);
|
722
|
+
$('.hy-e').toggleClass('hy-edit-active', 250);
|
723
|
+
},
|
724
|
+
replaceElement: function(link) {
|
725
|
+
|
726
|
+
}
|
727
|
+
}
|
728
|
+
|
729
|
+
|
730
|
+
$('form[data-dialog-remote]').live('submit', function(e) {
|
731
|
+
$.humpyard.submitForm($(this), $(this).parents('.ui-dialog-content:first'));
|
732
|
+
e.preventDefault();
|
733
|
+
});
|
734
|
+
|
735
|
+
$('div[data-dialog-remote]:not([data-remote]) a, a[data-dialog-remote]:not([data-remote])').live('click', function(e) {
|
736
|
+
$.humpyard.dialogLink($(this), $(this).parents('.ui-dialog-content:first'));
|
737
|
+
e.preventDefault();
|
738
|
+
});
|
739
|
+
|
740
|
+
|
741
|
+
$('a[data-command],input[data-command]').live('click', function (e) {
|
742
|
+
commands[$(this).attr('data-command')]($(this));
|
743
|
+
e.preventDefault();
|
744
|
+
});
|
745
|
+
|
746
|
+
$('a[data-dialog-method]').live('click', function(e) {
|
747
|
+
var link = $(this),
|
748
|
+
href = link.attr('href'),
|
749
|
+
method = link.attr('data-dialog-method'),
|
750
|
+
form = $('<form method="post" action="'+href+'">'),
|
751
|
+
metadata_input = '<input name="_method" value="'+method+'" type="hidden" />';
|
752
|
+
|
753
|
+
if (typeof(csrf_param) != 'undefined' && typeof(csrf_token) != 'undefined') {
|
754
|
+
if(csrf_param && csrf_token) {
|
755
|
+
metadata_input += '<input name="'+csrf_param+'" value="'+csrf_token+'" type="hidden" />';
|
756
|
+
}
|
757
|
+
} else {
|
758
|
+
throw "No CSRF token found (is csrf_meta_tag in your layout?).";
|
759
|
+
}
|
760
|
+
|
761
|
+
form.hide()
|
762
|
+
.append(metadata_input)
|
763
|
+
.appendTo('body');
|
764
|
+
|
765
|
+
e.preventDefault();
|
766
|
+
|
767
|
+
$.humpyard.submitForm(form, $(this).parents('.ui-dialog-content:first'), link.parents('form:first'));
|
768
|
+
});
|
769
|
+
|
770
|
+
$('a[data-dialog-menu]').live('click', function(e) {
|
771
|
+
var link = $(this);
|
772
|
+
|
773
|
+
$(link.attr('data-dialog-menu')).toggle();
|
774
|
+
|
775
|
+
e.preventDefault();
|
776
|
+
});
|
777
|
+
|
778
|
+
$('.dialog-menu a').live('click', function(e) {
|
779
|
+
$('.dialog-menu').hide();
|
780
|
+
});
|
781
|
+
});
|
782
|
+
|
783
|
+
remove_element = function(el) {
|
784
|
+
$(el).remove();
|
785
|
+
};
|
786
|
+
|
787
|
+
replace_content_for_element = function(el, content) {
|
788
|
+
$(el).html(content);
|
789
|
+
}
|
790
|
+
|