saving editable text elements works
This commit is contained in:
parent
1e8376d18f
commit
fc7fef8ba3
1
doc/TODO
1
doc/TODO
@ -13,6 +13,7 @@ BOARD:
|
|||||||
- edit images (upload new ones, ...etc)
|
- edit images (upload new ones, ...etc)
|
||||||
- google analytics tags (only visible in non edit mode)
|
- google analytics tags (only visible in non edit mode)
|
||||||
- locale
|
- locale
|
||||||
|
- trim short text content
|
||||||
- global regions: keyword in editable element
|
- global regions: keyword in editable element
|
||||||
- create a repo for a tool "a la" vision
|
- create a repo for a tool "a la" vision
|
||||||
- write my first tutorial about locomotive
|
- write my first tutorial about locomotive
|
||||||
|
@ -6,16 +6,17 @@ module Liquid
|
|||||||
def render(context)
|
def render(context)
|
||||||
if context.registers[:current_admin]
|
if context.registers[:current_admin]
|
||||||
output = %{
|
output = %{
|
||||||
|
<meta name="locale" content="#{I18n.locale}" />
|
||||||
<meta name="page-fullpath" content="/#{context.registers[:page].fullpath}" />
|
<meta name="page-fullpath" content="/#{context.registers[:page].fullpath}" />
|
||||||
<meta name="edit-page-url" content="#{context.registers[:controller].send(:edit_admin_page_url, context.registers[:page])}" />
|
<meta name="edit-page-url" content="#{context.registers[:controller].send(:edit_admin_page_url, context.registers[:page])}" />
|
||||||
|
|
||||||
<script src="/javascripts/admin/jquery.js" type="text/javascript"></script>
|
|
||||||
<script src="/javascripts/admin/rails.js" type="text/javascript"></script>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if context.registers[:inline_editor]
|
if context.registers[:inline_editor]
|
||||||
|
controller = context.registers[:controller]
|
||||||
|
|
||||||
output << %{
|
output << %{
|
||||||
<meta name="page-url" content="#{context.registers[:controller].send(:admin_page_url, context.registers[:page])}" />
|
<meta name="page-url" content="#{context.registers[:controller].send(:admin_page_url, context.registers[:page], :json)}" />
|
||||||
|
<meta name="page-elements-count" content="#{context.registers[:page].editable_elements.size}" />
|
||||||
|
|
||||||
<script type="text/javascript" src="/javascripts/admin/aloha/aloha.js"></script>
|
<script type="text/javascript" src="/javascripts/admin/aloha/aloha.js"></script>
|
||||||
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js"></script>
|
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Format/plugin.js"></script>
|
||||||
@ -24,9 +25,18 @@ module Liquid
|
|||||||
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js"></script>
|
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.Link/plugin.js"></script>
|
||||||
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js"></script>
|
<script type="text/javascript" src="/javascripts/admin/aloha/plugins/com.gentics.aloha.plugins.HighlightEditables/plugin.js"></script>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if controller.send(:protect_against_forgery?)
|
||||||
|
output << %(<meta name="csrf-param" content="#{Rack::Utils.escape_html(controller.send(:request_forgery_protection_token))}"/>\n<meta name="csrf-token" content="#{Rack::Utils.escape_html(controller.send(:form_authenticity_token))}"/>).html_safe
|
||||||
|
end
|
||||||
|
else
|
||||||
|
output << %{
|
||||||
|
<script src="/javascripts/admin/jquery.js" type="text/javascript"></script>
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
output << %{
|
output << %{
|
||||||
|
<script src="/javascripts/admin/rails.js" type="text/javascript"></script>
|
||||||
<script type="text/javascript" src="/javascripts/admin/inline_editor.js"></script>
|
<script type="text/javascript" src="/javascripts/admin/inline_editor.js"></script>
|
||||||
<link href="/stylesheets/admin/inline_editor.css" media="screen" rel="stylesheet" type="text/css" />
|
<link href="/stylesheets/admin/inline_editor.css" media="screen" rel="stylesheet" type="text/css" />
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,6 @@ module Mongoid #:nodoc:
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
# http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb
|
# http://github.com/emk/mongoid/blob/503e346b1b7b250d682a12332ad9d5872f1575e6/lib/mongoid/atomicity.rb
|
||||||
module Mongoid #:nodoc:
|
module Mongoid #:nodoc:
|
||||||
module Atomicity #:nodoc:
|
module Atomicity #:nodoc:
|
||||||
|
@ -1,8 +1,57 @@
|
|||||||
|
var foo = bar = null;
|
||||||
|
// var foo = null;
|
||||||
|
|
||||||
|
var prepareForm = function(jEvent, aEvent) {
|
||||||
|
// console.log('foo !!!');
|
||||||
|
// console.log(ui.editable.getContents());
|
||||||
|
$('#page-toolbar li.save, #page-toolbar li.cancel, #page-toolbar li.sep:eq(1)').show();
|
||||||
|
|
||||||
|
var element = $(aEvent.editable.obj[0]);
|
||||||
|
// var id = element.attr('data-element-id');
|
||||||
|
var index = element.attr('data-element-index');
|
||||||
|
|
||||||
|
// console.log('id = ' + id + ', index = ' + index);
|
||||||
|
|
||||||
|
// if ($('#page-toolbar form editable-' + index).length > 0) return;
|
||||||
|
//
|
||||||
|
// $('#page-toolbar form').append("\
|
||||||
|
// <input id='editable-" + index +"' class='auto' type='hidden' name='page[editable_elements_attributes][" + index + "][id]' value='" + id + "' />\
|
||||||
|
// <input class='auto' type='hidden' name='page[editable_elements_attributes][" + index + "][_index]' value='" + index + "' />\
|
||||||
|
// <input class='auto' type='hidden' name='page[editable_elements_attributes][" + index + "][content]' />\
|
||||||
|
// ");
|
||||||
|
|
||||||
|
// $('#page-toolbar form input:last').val(aEvent.editable.getContents());
|
||||||
|
|
||||||
|
var input = $('#page-toolbar form #editable-' + index);
|
||||||
|
|
||||||
|
input.attr('name', input.attr('name').replace('_index', 'content'));
|
||||||
|
input.val(aEvent.editable.getContents());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// foo = $(this);
|
||||||
|
|
||||||
|
// $(foo.editable.obj[0])
|
||||||
|
|
||||||
|
// console.log($(this).attr('data-element-id'));
|
||||||
|
|
||||||
|
// bar = a;
|
||||||
|
// foo = ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
var resetForm = function() {
|
||||||
|
$('#page-toolbar form input.auto').each(function() {
|
||||||
|
$(this).attr('name', $(this).attr('name').replace('content', '_index'));
|
||||||
|
$(this).val('');
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#page-toolbar li.save, #page-toolbar li.cancel, #page-toolbar li.sep:eq(1)').hide();
|
||||||
|
}
|
||||||
|
|
||||||
if (typeof GENTICS != 'undefined') {
|
if (typeof GENTICS != 'undefined') {
|
||||||
GENTICS.Aloha.settings = {
|
GENTICS.Aloha.settings = {
|
||||||
errorhandling : false,
|
errorhandling : false,
|
||||||
ribbon: false,
|
ribbon: false,
|
||||||
"i18n": {"current": "en"},
|
|
||||||
"plugins": {
|
"plugins": {
|
||||||
// "com.gentics.aloha.plugins.GCN": {
|
// "com.gentics.aloha.plugins.GCN": {
|
||||||
// "enabled": false
|
// "enabled": false
|
||||||
@ -28,6 +77,8 @@ if (typeof GENTICS != 'undefined') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
GENTICS.Aloha.EventRegistry.subscribe(GENTICS.Aloha, "editableDeactivated", prepareForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
var editingMode = false;
|
var editingMode = false;
|
||||||
@ -36,10 +87,16 @@ var buildPageToolbar = function() {
|
|||||||
var fullpath = $('meta[name=page-fullpath]').attr('content');
|
var fullpath = $('meta[name=page-fullpath]').attr('content');
|
||||||
var showPageUrl = $('meta[name=page-url]').attr('content');
|
var showPageUrl = $('meta[name=page-url]').attr('content');
|
||||||
var editPageUrl = $('meta[name=edit-page-url]').attr('content');
|
var editPageUrl = $('meta[name=edit-page-url]').attr('content');
|
||||||
|
var nbElements = parseInt($('meta[name=page-elements-count]').attr('content'));
|
||||||
|
|
||||||
editingMode = typeof showPageUrl != 'undefined';
|
editingMode = typeof showPageUrl != 'undefined';
|
||||||
var style = editingMode ? '' : "style='display: none'"
|
var style = editingMode ? '' : "style='display: none'"
|
||||||
|
|
||||||
|
var formContentHTML = "<input type='hidden' name='_method' value='put' />";
|
||||||
|
for (var i = 0; i < nbElements; i++) {
|
||||||
|
formContentHTML += "<input class='auto' id='editable-" + i + "' type='hidden' name='page[editable_elements_attributes][" + i + "][_index]' value='' />";
|
||||||
|
}
|
||||||
|
|
||||||
$('body').prepend("<div id='page-toolbar'>\
|
$('body').prepend("<div id='page-toolbar'>\
|
||||||
<ul>\
|
<ul>\
|
||||||
<li class='drawer'><a href='#'><span> </span></a></li>\
|
<li class='drawer'><a href='#'><span> </span></a></li>\
|
||||||
@ -48,27 +105,55 @@ var buildPageToolbar = function() {
|
|||||||
<li class='link edit' style='" + (editingMode ? 'display: none' : '') + "'><a href='#'><span>edit</span></a></li>\
|
<li class='link edit' style='" + (editingMode ? 'display: none' : '') + "'><a href='#'><span>edit</span></a></li>\
|
||||||
<li class='link save' style='display: none'><a href='#'><span>save</span></a></li>\
|
<li class='link save' style='display: none'><a href='#'><span>save</span></a></li>\
|
||||||
<li class='link cancel' style='display: none'><a href='#'><span>cancel</span></a></li>\
|
<li class='link cancel' style='display: none'><a href='#'><span>cancel</span></a></li>\
|
||||||
|
<li class='sep' style='display: none'><span> </span></li>\
|
||||||
<li class='link back' style='" + (editingMode ? '' : 'display: none') + "'><a href='#'><span>back</span></a></li>\
|
<li class='link back' style='" + (editingMode ? '' : 'display: none') + "'><a href='#'><span>back</span></a></li>\
|
||||||
</ul>\
|
</ul>\
|
||||||
|
<form action='" + showPageUrl + "' accept-charset='UTF-8' method='post'>\
|
||||||
|
" + formContentHTML + "\
|
||||||
|
</form>\
|
||||||
</div>");
|
</div>");
|
||||||
|
|
||||||
// events
|
// build the form
|
||||||
|
$('#page-toolbar form').live('submit', function (e) {
|
||||||
|
$(this).callRemote();
|
||||||
|
e.stopPropagation();
|
||||||
|
e.preventDefault();
|
||||||
|
}).bind('ajax:complete', function() {
|
||||||
|
console.log('ajax:complete');
|
||||||
|
resetForm();
|
||||||
|
}).bind('ajax:failure', function() {
|
||||||
|
console.log('ajax:failure');
|
||||||
|
resetForm();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// events: save
|
||||||
|
$('#page-toolbar').find('.save').click(function(e) {
|
||||||
|
$('#page-toolbar form').submit();
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
|
||||||
|
// events: edit
|
||||||
$('#page-toolbar').find('.edit').click(function() {
|
$('#page-toolbar').find('.edit').click(function() {
|
||||||
url = window.location.href;
|
url = window.location.href;
|
||||||
if (url.charAt(url.length - 1) == '/') url += 'index';
|
if (url.charAt(url.length - 1) == '/') url += 'index';
|
||||||
window.location.href = url + '/edit';
|
window.location.href = url + '/edit';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// events: cancel
|
||||||
$('#page-toolbar').find('.cancel').click(function(e) {
|
$('#page-toolbar').find('.cancel').click(function(e) {
|
||||||
e.preventDefault(); e.stopPropagation();
|
e.preventDefault(); e.stopPropagation();
|
||||||
window.location.href = window.location.href;
|
window.location.href = window.location.href;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// events: back
|
||||||
$('#page-toolbar').find('.back').click(function(e) {
|
$('#page-toolbar').find('.back').click(function(e) {
|
||||||
e.preventDefault(); e.stopPropagation();
|
e.preventDefault(); e.stopPropagation();
|
||||||
window.location.href = fullpath;
|
window.location.href = fullpath;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// drawer
|
||||||
$('#page-toolbar').find('.drawer a').eq(0).click(function() {
|
$('#page-toolbar').find('.drawer a').eq(0).click(function() {
|
||||||
var self = $(this);
|
var self = $(this);
|
||||||
var max = $('#page-toolbar').width() - 17;
|
var max = $('#page-toolbar').width() - 17;
|
||||||
@ -89,11 +174,14 @@ jQuery(document).ready(function($) {
|
|||||||
buildPageToolbar();
|
buildPageToolbar();
|
||||||
|
|
||||||
if (editingMode) {
|
if (editingMode) {
|
||||||
|
// set locale
|
||||||
|
GENTICS.Aloha.settings['i18n'] = { 'current': $('meta[name=locale]').attr('content') };
|
||||||
|
|
||||||
// add 'edit' at the end of each url of the page
|
// add 'edit' at the end of each url of the page
|
||||||
$('a').each(function() {
|
$('a').each(function() {
|
||||||
var url = $(this).attr('href');
|
var url = $(this).attr('href');
|
||||||
|
|
||||||
if (/^(www|http)/.exec(url) == null && /(\/edit)$/.exec(url) == null) {
|
if (url != '#' && /^(www|http)/.exec(url) == null && /(\/edit)$/.exec(url) == null) {
|
||||||
if (url == '/') url = '/index';
|
if (url == '/') url = '/index';
|
||||||
$(this).attr('href', url + '/edit');
|
$(this).attr('href', url + '/edit');
|
||||||
}
|
}
|
||||||
@ -125,6 +213,5 @@ jQuery(document).ready(function($) {
|
|||||||
|
|
||||||
self.aloha();
|
self.aloha();
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -23,18 +23,19 @@ jQuery(function ($) {
|
|||||||
*/
|
*/
|
||||||
callRemote: function () {
|
callRemote: function () {
|
||||||
var el = this,
|
var el = this,
|
||||||
data = el.is('form') ? el.serializeArray() : [],
|
|
||||||
method = el.attr('method') || el.attr('data-method') || 'GET',
|
method = el.attr('method') || el.attr('data-method') || 'GET',
|
||||||
url = el.attr('action') || el.attr('href');
|
url = el.attr('action') || el.attr('href'),
|
||||||
|
dataType = el.attr('data-type') || 'script';
|
||||||
|
|
||||||
if (url === undefined) {
|
if (url === undefined) {
|
||||||
throw "No URL specified for remote call (action or href must be present).";
|
throw "No URL specified for remote call (action or href must be present).";
|
||||||
} else {
|
} else {
|
||||||
if (el.triggerAndReturn('ajax:before')) {
|
if (el.triggerAndReturn('ajax:before')) {
|
||||||
|
var data = el.is('form') ? el.serializeArray() : [];
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: url,
|
url: url,
|
||||||
data: data,
|
data: data,
|
||||||
dataType: 'script',
|
dataType: dataType,
|
||||||
type: method.toUpperCase(),
|
type: method.toUpperCase(),
|
||||||
beforeSend: function (xhr) {
|
beforeSend: function (xhr) {
|
||||||
el.trigger('ajax:loading', xhr);
|
el.trigger('ajax:loading', xhr);
|
||||||
@ -104,24 +105,28 @@ jQuery(function ($) {
|
|||||||
/**
|
/**
|
||||||
* disable-with handlers
|
* disable-with handlers
|
||||||
*/
|
*/
|
||||||
var disable_with_input_selector = 'input[data-disable-with]';
|
var disable_with_input_selector = 'input[data-disable-with]';
|
||||||
var disable_with_form_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
|
var disable_with_form_remote_selector = 'form[data-remote]:has(' + disable_with_input_selector + ')';
|
||||||
|
var disable_with_form_not_remote_selector = 'form:not([data-remote]):has(' + disable_with_input_selector + ')';
|
||||||
|
|
||||||
$(disable_with_form_selector).live('ajax:before', function () {
|
var disable_with_input_function = function () {
|
||||||
$(this).find(disable_with_input_selector).each(function () {
|
$(this).find(disable_with_input_selector).each(function () {
|
||||||
var input = $(this);
|
var input = $(this);
|
||||||
input.data('enable-with', input.val())
|
input.data('enable-with', input.val())
|
||||||
.attr('value', input.attr('data-disable-with'))
|
.attr('value', input.attr('data-disable-with'))
|
||||||
.attr('disabled', 'disabled');
|
.attr('disabled', 'disabled');
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
$(disable_with_form_selector).live('ajax:after', function () {
|
$(disable_with_form_remote_selector).live('ajax:before', disable_with_input_function);
|
||||||
|
$(disable_with_form_not_remote_selector).live('submit', disable_with_input_function);
|
||||||
|
|
||||||
|
$(disable_with_form_remote_selector).live('ajax:complete', function () {
|
||||||
$(this).find(disable_with_input_selector).each(function () {
|
$(this).find(disable_with_input_selector).each(function () {
|
||||||
var input = $(this);
|
var input = $(this);
|
||||||
input.removeAttr('disabled')
|
input.removeAttr('disabled')
|
||||||
.val(input.data('enable-with'));
|
.val(input.data('enable-with'));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user