Permalink
Browse files

Multilocale cms

commit 9bc3e360f5e4e1b597e921a537e64c8741ac579b
Author: pyromaniac <kinwizard@gmail.com>
Date:   Wed Sep 19 18:26:02 2012 +0700

    Fixed localized interface

commit 7c5c6ebd0d9514dde446b0a879c811df59aa8696
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Tue Aug 28 19:06:09 2012 +0800

    minor edits

commit a3b1f659f04fcd6c6d120dc7439bc1445a95306b
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Tue Aug 28 19:01:03 2012 +0800

    locale fallback and turning localization on/off

commit 156545c81686c7d1d8b9a535def3ce12675e5e89
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Mon Aug 27 17:38:55 2012 +0800

    ui support for disabled/enabled locales

commit fc2e4251d1102116b77a52161d55484112d6a2a9
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Thu Aug 23 22:13:31 2012 +0800

    page.all_inherited_page_parts rewritten to make all old specs pass

commit b844ea3f34ad1e12e97c8e1f86f44d04834a02b4
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Thu Aug 23 18:05:50 2012 +0800

    render only page parts of current locale

commit 9612ace8a48d9fbabf6325e94943780d1fba7166
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Wed Aug 22 21:23:28 2012 +0800

    completed js code for multilocale UI

commit a867abee464e1a82651319fa8f8626cae5611a2a
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Tue Aug 21 16:36:12 2012 +0800

    part with default locale added, restyled locale buttons, all locale removed with a part, a new locale added to a part

commit 736d4ef26851a4f28180eed40b2bd6afbcf7c7ca
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Mon Aug 20 16:47:30 2012 +0800

    minor changes

commit 7116b12fe35e748f09fabd8dfa4b6a705f94522f
Author: Andrew Gridnev <andrew.gridnev@gmail.com>
Date:   Mon Aug 20 16:42:18 2012 +0800

    multiple locales supported in page parts
  • Loading branch information...
1 parent 13dcef4 commit 50f734402ce2caaa20fe330276c91ca3c5251407 @pyromaniac pyromaniac committed Sep 19, 2012
@@ -5,18 +5,20 @@
//= require puffer/codemirror/javascript
//= require puffer/codemirror/css
//= require_tree ./codemirror
-//= require puffer/liquid
Tabs.include({
- initialize: function(options) {
- this.$super(options);
+ initialize: function(element, options) {
+ this.$super(element, options);
this.buildAddButton();
},
buildAddButton: function() {
if (isFunction(this.options.addButton)) {
this.addButton = $E('a', {'class': 'rui-tabs-tab rui-tabs-add', 'html': '<a href="#">+</a>'}).insertTo(this.tabsList);
this.addButton.onClick(this.options.addButton.bind(this));
+ this.onAdd(function(event) {
+ this.addButton.insertTo(this.tabsList);
+ });
}
},
@@ -42,37 +44,118 @@ Tabs.include({
}
});
+Tabs.Tab.include({
+ initialize: function(element, main) {
+ this.$super(element, main);
+ if (main.options.disablable) {
+ this.link.insert($E('div', {
+ 'class': 'rui-tabs-tab-close-icon', 'html': '&times;'
+ }).onClick(function(event) {
+ if (this.main.enabled().length > 1) {
+ if (this.current()) {
+ var enabled = this.main.enabled();
+ var sibling = enabled[enabled.indexOf(this) + 1] || enabled[enabled.indexOf(this)-1];
+
+ if (sibling) {
+ sibling.select();
+ }
+ }
+ this.disable();
+ }
+ event.stop();
+ }.bind(this)));
+ }
+ }
+});
+
var page_part_tab_select = function(event) {
+ var inner_tabs = event.target.panel.find('.rui-tabs,*[data-tabs]').first();
+ if (inner_tabs instanceof Tabs)
+ inner_tabs.current().select();
+
var textarea = event.target.panel.first('textarea[data-codemirror]');
- if (textarea.codemirror) {
+ if (textarea && textarea.codemirror) {
textarea.codemirror.refresh();
}
}
-var page_part_tab_remove = function(event) {
- var destroy_mark = event.target.panel.first('.destroy_mark');
- var page_part_param = destroy_mark.next();
- $('page_parts_marked_for_destroy').append(destroy_mark.value('1'))
- if (page_part_param) {
- $('page_parts_marked_for_destroy').append(page_part_param);
- }
-}
-
var page_part_tab_add = function(event) {
- event.stop();
- var new_id = new Date().getTime();
var _this = this;
+
new Dialog.Prompt({label: 'Enter new page part name'}).onOk(function() {
var value = this.input.value();
if (!value.blank()) {
- _this.add(value, new_page_part_tab_panel.replace(/new_page_part_tab_panel_index/g, new_id), {id: new_id});
- _this.tabs.last().panel.first('input[type=hidden]').value(value);
- _this.tabs.last().select();
- _this.addButton.insertTo(_this.tabsList);
- $$('textarea[data-codemirror]').each(init_codemirror);
+ _this.add(value);
+ var tab = _this.tabs.last();
+ tab.panel.data('name', value);
+ fill_new_tab(tab);
+ tab.select();
+
+ Tabs.rescan();
+ init_codemirrors();
this.hide();
}
}).show();
+ event.stop();
+}
+
+var page_part_tab_remove = function(event) {
+ save_destroy_marks(event.target.panel);
+}
+
+var page_part_locale_select = function(event) {
+ if (!event.target.enabled())
+ event.target.enable();
+ if (!event.target.current())
+ event.target.select();
+
+ if (event.target.panel.html().blank())
+ fill_new_tab(event.target);
+
+ var textarea = event.target.panel.first('textarea[data-codemirror]');
+ if (textarea && textarea.codemirror) {
+ textarea.codemirror.refresh();
+ }
+}
+
+var page_part_locale_enable = function(event) {
+ fill_new_tab(event.target);
+}
+
+var page_part_locale_disable = function(event) {
+ save_destroy_marks(event.target.panel);
+ event.target.panel.update();
+}
+
+var fill_new_tab = function(tab) {
+ var new_id = new Date().getTime();
+ if (tab.main.data('new-panel'))
+ tab.panel.update(tab.main.data('new-panel').replace(new RegExp(tab.main.data('new-panel-variable'), 'g'), new_id));
+
+ var name_input = tab.panel.first('[data-acts="name"]');
+ var name_panel = tab.panel.first().parent('[data-name]');
+ if (name_input && name_panel) {
+ name_input.value(name_panel.data('name'));
+ }
+
+ var locale_input = tab.panel.first('[data-acts="locale"]');
+ var locale = tab.data('locale');
+ if (locale_input && locale) {
+ locale_input.value(locale);
+ }
+
+ init_codemirrors();
+}
+
+var save_destroy_marks = function(scope) {
+ var form = scope.tab.main.parent('form');
+ scope.find('[data-acts="destroy"]').each(function(destroy_mark) {
+ var page_part_param = destroy_mark.siblings('[data-acts="id"]').first();
+ if (page_part_param) {
+ form.append(destroy_mark.value('true'));
+ form.append(page_part_param);
+ }
+ });
}
var init_codemirror = function(textarea) {
@@ -83,13 +166,6 @@ var init_codemirror = function(textarea) {
lineWrapping: true,
matchBrackets: true,
tabSize: 2,
- // onCursorActivity: function(editor) {
- // if (editor.last_active_line != undefined) {
- // editor.setLineClass(editor.last_active_line, null);
- // }
- // editor.last_active_line = editor.getCursor().line;
- // editor.setLineClass(editor.last_active_line, "active_line");
- // },
extraKeys: {
"Tab": "indentMore",
"Shift-Tab": "indentLess",
@@ -103,8 +179,12 @@ var init_codemirror = function(textarea) {
}
}
-$(document).onReady(function() {
+var init_codemirrors = function() {
$$('textarea[data-codemirror]').each(init_codemirror);
+}
+
+$(document).onReady(function() {
+ init_codemirrors();
});
$(document).on('data:sending', function() {
@@ -115,7 +195,7 @@ $(document).on('data:sending', function() {
$(document).on('ajax:complete', function() {
Tabs.rescan();
- $$('textarea[data-codemirror]').each(init_codemirror);
+ init_codemirrors();
});
"*[data-codemirror-button]".onClick(function(event) {
@@ -35,6 +35,26 @@ div.CodeMirror span.CodeMirror-matchingbracket
min-height: 300px;
}
+#page_parts .localized-tabs {
+ border: 0;
+}
+
+#page_parts .localized-tabs .rui-tabs-panel {
+ border: 0;
+}
+
+#page_parts .localized-tabs .rui-tabs-list {
+ border: 0;
+ z-index: 100;
+ position: absolute;
+ right: 0;
+ top: 0;
+}
+
+#page_parts .localized-tabs .rui-tabs-tab a {
+ border: 0;
+}
+
.active_line {
background: #eee !important;
}
@@ -64,6 +84,59 @@ div.CodeMirror span.CodeMirror-matchingbracket
cursor: pointer;
}
+.codemirror_buttons li.locales-group-item,
+.codemirror_buttons li.selected-locales-group-item,
+.codemirror_buttons .unavailable-locales-group-item {
+ border-radius: 3px;
+ padding: 2px 8px;
+ margin: 2px 2px;
+ float: right;
+}
+
+.codemirror_buttons li.locales-group-item {
+ background: #ddd;
+}
+
+.codemirror_buttons li.selected-locales-group-item {
+ background: #3D576D;
+ color: white;
+}
+
+ul.codemirror_buttons li.selected-locales-group-item a.remove-locale {
+ color: #ddd;
+ font-size: 12px;
+ text-decoration: none;
+ display: inline-block;;
+ margin-left: 4px;
+}
+
+ul.codemirror_buttons li.selected-locales-group-item a.remove-locale:hover {
+ color: #f44;
+}
+
+ul.codemirror_buttons li.locales-group-item a.remove-locale {
+ color: #333;
+ font-size: 12px;
+ text-decoration: none;
+ display: inline-block;;
+ margin-left: 4px;
+}
+
+ul.codemirror_buttons li.locales-group-item a.remove-locale:hover {
+ color: #c00;
+}
+
+.codemirror_buttons li.unavailable-locales-group-item {
+ background: white;
+ color: gray;
+ border: 1px solid #ccc;
+ margin: 1px 2px;
+}
+
+.codemirror_buttons li:hover.selected-locales-group-item {
+ color: #fff;
+}
+
.codemirror_buttons li:hover {
color: #ff6600;
}
@@ -0,0 +1,6 @@
+<%= form.fields_for field.name, page_part, :child_index => child_index do |page_part_builder| %>
+ <% field.children.each do |field| %>
+ <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
+ <% end %>
+ <%= page_part_builder.hidden_field :id, :data => { :acts => 'id' } if page_part_builder.object.persisted? %>
+<% end %>
@@ -0,0 +1,18 @@
+<ul class="rui-tabs localized-tabs" data-tabs="{disablable: true, onSelect: page_part_locale_select, onEnable: page_part_locale_enable, onDisable: page_part_locale_disable}" data-new-panel="<%= render('page_part', :form => form, :page_part => PagePart.new, :child_index => 'new_tab_panel_locale_index').gsub(/\n/, '').strip %>" data-new-panel-variable="new_tab_panel_locale_index">
+ <ul class="rui-tabs-list">
+ <% I18n.available_locales.each do |locale| %>
+ <li class="rui-tabs-tab<%= ' rui-tabs-disabled' unless page_parts[locale] || locale == I18n.default_locale %>" data-locale="<%= locale %>">
+ <%= link_to "#page_part_tab_#{index}_#{locale}" do %>
+ <%= locale.to_s.humanize %>
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
+ <% I18n.available_locales.each do |locale| %>
+ <% if page_parts[locale] %>
+ <li id="<%= "page_part_tab_#{index}_#{locale}" %>" class="rui-tabs-panel">
+ <%= render 'page_part', :form => form, :page_part => page_parts[locale], :child_index => child_index %>
+ </li>
+ <% end %>
+ <% end %>
+</ul>
@@ -1,8 +1,9 @@
-<%= fields_for @record do |f| %>
- <ul id="<%= field.name %>" class="rui-tabs" data-tabs="{closable: true, scrollTabs: true, Cookie: {}, onSelect: page_part_tab_select, onRemove: page_part_tab_remove, addButton: page_part_tab_add}">
+<%= component_fields_for @record do |f| %>
+ <ul id="<%= field.name %>" class="rui-tabs" data-tabs="{closable: true, scrollTabs: true, Cookie: {}, onSelect: page_part_tab_select, onRemove: page_part_tab_remove, addButton: page_part_tab_add}" data-new-panel="<%= (localized? ? render('page_part_locales', :form => f, :page_parts => {}, :index => 'new_tab_panel_index') : render('page_part', :form => f, :page_part => PagePart.new, :child_index => 'new_tab_panel_index')).gsub(/\n/, '').strip %>" data-new-panel-variable="new_tab_panel_index">
<ul class="rui-tabs-list">
- <% @record.send(field.name).each_with_index do |page_part, index| %>
- <li>
+ <% @record.send(localized? ? "#{field.name}_translations" : field.name).each_with_index do |page_part, index| %>
+ <% page_part = page_part.values.first if localized? %>
+ <li class="rui-tabs-tab">
<%= link_to "#page_part_tab_#{index}" do %>
<%= page_part.name %>
<% if page_part.errors[:name].present? %>
@@ -14,29 +15,14 @@
</li>
<% end %>
</ul>
- <% @record.send(field.name).each_with_index do |page_part, index| -%>
- <li id="<%= "page_part_tab_#{index}" %>" class="rui-tabs-panel">
- <%= f.fields_for field.name, page_part do |page_part_builder| %>
- <% field.children.each do |field| %>
- <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
- <% end %>
- <%= page_part_builder.hidden_field :id unless page_part_builder.object.persisted? %>
+ <% @record.send(localized? ? "#{field.name}_translations" : field.name).each_with_index do |page_part, index| -%>
+ <li id="<%= "page_part_tab_#{index}" %>" class="rui-tabs-panel" data-name="<%= localized? ? page_part.values.first.name : page_part.name %>">
+ <% if localized? %>
+ <%= render 'page_part_locales', :form => f, :page_parts => page_part, :index => index, :child_index => nil %>
+ <% else %>
+ <%= render 'page_part', :form => f, :page_part => page_part, :child_index => nil %>
<% end %>
</li>
<% end -%>
</ul>
- <div id="page_parts_marked_for_destroy">
- </div>
-
- <% new_page_part_tab_panel = capture do %>
- <%= f.fields_for field.name, PagePart.new, :child_index => 'new_page_part_tab_panel_index' do |page_part_builder| %>
- <% field.children.each do |field| %>
- <%= field.render :form, parent_controller, page_part_builder.object, :builder => page_part_builder %>
- <% end %>
- <% end %>
- <% end %>
-
- <%= javascript_tag do %>
- var new_page_part_tab_panel = '<%= j new_page_part_tab_panel.strip.html_safe %>'
- <% end %>
<% end %>
@@ -1,7 +1,15 @@
class PagePartsComponent < Puffer::Component::Base
+ helper_method :localized?
+
def form
render
end
+private
+
+ def localized?
+ !!field.options[:localized]
+ end
+
end
@@ -0,0 +1,5 @@
+class AddLocaleToPageParts < ActiveRecord::Migration
+ def change
+ add_column :page_parts, :locale, :string
+ end
+end
View
@@ -28,6 +28,13 @@ class LayoutMissed < PufferPagesError
mattr_accessor :codemirror_buttons
self.codemirror_buttons = [:fullscreen]
+ mattr_accessor :localize
+ self.localize = false
+
+ def self.localize?
+ localize == true
+ end
+
def self.setup
yield self
end
Oops, something went wrong.

0 comments on commit 50f7344

Please sign in to comment.