Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added simple translations and page

  • Loading branch information...
commit e154eef92c11439ee1af6e5d8459f334754dcef5 1 parent a81e066
Marek authored
6 nbproject/private/private.xml
View
@@ -1,10 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-private xmlns="http://www.netbeans.org/ns/project-private/1">
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/>
- <open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/1">
- <file>file:/home/web-data/work/refinery/refinerycms-js/libs/builder/componentbuild/refinerycms/macrolib.xml</file>
- <file>file:/home/web-data/work/refinery/refinerycms-js/libs/builder/componentbuild/refinerycms/properties.xml</file>
- <file>file:/home/web-data/work/refinery/refinerycms-js/libs/builder/componentbuild/refinerycms/rollup.xml</file>
- <file>file:/home/web-data/work/refinery/refinerycms-js/libs/builder/componentbuild/refinerycms/targets.xml</file>
- </open-files>
</project-private>
7 nbproject/project.properties
View
@@ -3,13 +3,16 @@ file.reference.scripts-build=./build
file.reference.scripts-docs=./docs
file.reference.scripts-tests=./tests
file.reference.scripts-temp=./temp
+file.reference.test-yui3=../../../libs/test/yui3
+file.reference.web-data-libs=../../../libs
ignore.path=\
${file.reference.scripts-build}:\
${file.reference.scripts-docs}:\
${file.reference.scripts-tests}:\
${file.reference.scripts-temp}
include.path=\
- ${file.reference.scripts-libs}
+ ${file.reference.scripts-libs}:\
+ ${file.reference.test-yui3}
php.version=PHP_53
phpunit.bootstrap=
phpunit.bootstrap.create.tests=false
@@ -20,6 +23,6 @@ source.encoding=UTF-8
src.dir=./src
tags.asp=false
tags.short=false
-test.src.dir=./tests
+test.src.dir=tests
web.root=.
project.license=default
0  src/page/README
View
No changes.
4 src/page/build.properties
View
@@ -0,0 +1,4 @@
+builddir=../../libs/builder/componentbuild
+
+component=page
+component.jsfiles=page.js
9 src/page/build.xml
View
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project name="RefineryCMS" default="local">
+ <property environment="env" />
+
+ <property file="build.properties" />
+
+ <import file="${builddir}/refinerycms/bootstrap.xml"
+ description="Default Build Properties and Targets" />
+</project>
159 src/page/js/page.js
View
@@ -0,0 +1,159 @@
+/**
+*
+* @todo Description
+* @version $Id$
+* @package refinerycms-js
+* @copyright Copyright (C) 2011
+* @author keraM marek@keram.name http//keram.name
+* @license MIT
+*/
+
+REFINERYCMS.page = {
+ initialised: false,
+ tabs: null,
+ strings: {
+ 'new_page_part_dialog_title': 'Create Content Section',
+ 'not_entered_title': 'You have not entered a title for the content section, please enter one.',
+ 'sure_delete_page_part': 'This will remove the content section {l_quote}{section_title}{r_quote} immediately. \nAre you sure?',
+ 'title_already_exists': 'A content section with that title already exists, please choose another.'
+ },
+
+ show_options: function () {
+ $('#toggle_advanced_options').click(function(e){
+ e.preventDefault();
+ $('#more_options').animate({
+ opacity: 'toggle',
+ height: 'toggle'
+ }, 250);
+
+ $('html,body').animate({
+ scrollTop: $('#toggle_advanced_options').parent().offset().top
+ }, 250);
+ });
+ },
+
+ title_type: function () {
+ $('#page_custom_title').parents('.field').find('input:radio').change(function(){
+ $('#custom_title_text, #custom_title_image').hide();
+ $('#custom_title_' + this.value).show();
+ });
+ },
+
+ page_part_dialog: function () {
+ var that = this;
+ var new_page_part_title = $('#new_page_part_title'),
+ new_page_part_dialog = $('#new_page_part_dialog'),
+ new_page_part_index = $('#new_page_part_index'),
+ page_part_editors = $('#page_part_editors');
+
+ new_page_part_dialog.dialog({
+ title: that.strings.new_page_part_dialog_title,
+ modal: true,
+ resizable: false,
+ autoOpen: false,
+ width: 600,
+ height: 200
+ });
+
+ $('#add_page_part').click(function(e){
+ e.preventDefault();
+ new_page_part_dialog.dialog('open');
+ });
+
+ $('#new_page_part_save').click(function(e){
+ e.preventDefault();
+
+ var part_title = new_page_part_title.val();
+
+ if(part_title.length > 0){
+ var tab_title = part_title.toLowerCase().replace(" ", "_");
+
+ if ($('#part_' + tab_title).size() === 0) {
+ $.get(that.new_part_url, {
+ title: part_title,
+ part_index: new_page_part_index.val(),
+ body: ''
+ }, function(data, status){
+ $('#submit_continue_button').remove();
+ // Add a new tab for the new content section.
+ $(data).appendTo(page_part_editors);
+ that.tabs.tabs('add', '#page_part_new_' + new_page_part_index.val(), part_title);
+ that.tabs.tabs('select', new_page_part_index.val());
+
+ // hook into wymedtior to instruct it to select this new tab again once it has loaded.
+ WYMeditor.onload_functions.push(function() {
+ $('#page_part_new_' + new_page_part_index.val()).appendTo(page_part_editors);
+ that.tabs.tabs('select', new_page_part_index.val());
+ });
+
+ // turn the new textarea into a wymeditor.
+ WYMeditor.init();
+
+ // Wipe the title and increment the index counter by one.
+ new_page_part_index.val(parseInt(new_page_part_index.val(), 10) + 1);
+ new_page_part_title.val('');
+
+ new_page_part_dialog.dialog('close');
+ new_page_part_dialog.remove();
+ }
+ );
+ } else {
+ alert(that.strings.title_already_exists);
+ }
+ } else {
+ alert(that.strings.not_entered_title);
+ }
+ });
+
+ $('#new_page_part_cancel').click(function(e){
+ e.preventDefault();
+ new_page_part_dialog.dialog('close');
+ new_page_part_title.val('');
+ });
+
+ $('#delete_page_part').click(function(e){
+ e.preventDefault();
+ //
+ // todo template
+// if(confirm(that.strings.confirm_delete, $('#page_parts .ui-tabs-selected a').text())) {
+ if(confirm(that.strings.confirm_delete)) {
+ var tabId = that.tabs.tabs('option', 'selected');
+ $.ajax({
+ url: that.del_part_url + '/' + $('#page_parts_attributes_' + tabId + '_id').val(),
+ type: 'DELETE'
+ });
+ that.tabs.tabs('remove', tabId);
+ $('#page_parts_attributes_' + tabId + '_id').remove();
+ $('#submit_continue_button').remove();
+ }
+
+ });
+
+ },
+
+ init: function () {
+ var part_shown = $('#page-tabs .page_part.field').not('.ui-tabs-hide');
+
+ this.tabs = $('#page-tabs');
+ this.tabs.tabs({
+ tabTemplate: '<li><a href="#{href}">#{label}</a></li>'
+ });
+
+ $('#page-tabs .page_part.field').removeClass('ui-tabs-hide');
+
+
+ this.enable_parts = enable_parts;
+ this.new_part_url = new_part_url;
+ this.del_part_url = del_part_url;
+ this.show_options();
+ this.title_type();
+
+ // hide the tabs that are supposed to be hidden.
+ $('#page-tabs .page_part.field').not(part_shown).addClass('ui-tabs-hide');
+
+ if(this.enable_parts){
+ this.page_part_dialog();
+ }
+ this.initialised = true;
+ }
+};
81 src/refinerycms/js/refinerycms.js
View
@@ -21,10 +21,55 @@
var REFINERYCMS = REFINERYCMS || {};
REFINERYCMS = {
+ lang: 'en',
+
+ strings: [],
+ // just until creating a better
+ // @todo
+ translate: function (string) {
+ var t = this.getTranslations(),
+ l = arguments.length,
+ rgxp_tpl = /{([a-zA-Z0-9_]+)}/;
+
+ if (typeof t[string] === 'undefined') {
+ return string;
+ }
+
+ if (typeof t[string] === 'function') {
+ return t[string].call(arguments);
+ }
+
+ if (l > 1 && typeof t[string] === 'string') {
+ var tmp_str = t[string];
+ for (var i = 1; i < l;i++) {
+ tmp_str = tmp_str.replace(rgxp_tpl, arguments[i]);
+ }
+
+ return tmp_str;
+ }
+
+ return t[string];
+ },
+
+ getTranslations: function () {
+ if (this.strings.length === 0) {
+ var strings = [];
+ if (typeof(this.translations[this.lang]) !== 'undefined') {
+ var translations = this.translations[this.lang];
+ for (string in translations) {
+ strings[string] = translations[string];
+ }
+ }
+ this.strings = strings;
+ }
+
+ return this.strings;
+ },
+
/**
* I love YUI namespaces
- *
+ *
* @see YUI.namespace
* @method namespace
* @param {string*} arguments 1-n namespaces to create.
@@ -35,17 +80,17 @@ REFINERYCMS = {
var a = arguments, o = null, i, j, d;
for (i = 0; i < a.length; i = i + 1) {
d = a[i].split(".");
-
+
o = window;
for (j = 0; j < d.length; j = j + 1) {
o[d[j]] = o[d[j]] || {};
o = o[d[j]];
}
}
-
+
return o;
},
-
+
/**
* Extend Child object with Parent prototype
*
@@ -73,3 +118,31 @@ REFINERYCMS = {
}
};
+REFINERYCMS.translations = {
+ 'sk' : {
+ 'prev' : 'Predchádzajúci',
+ 'next' : 'Následujúci',
+ 'from' : 'Od',
+ 'to' : 'Do',
+ 'l_quote' : '\u201E',
+ 'r_quote' : '\u201C'
+ },
+ 'cs' : {
+ 'prev' : 'P\u0159edchozí',
+ 'next' : 'Následující',
+ 'from' : 'Od',
+ 'to' : 'Do',
+ 'l_quote' : '\u201E',
+ 'r_quote' : '\u201C'
+ },
+ 'en' : {
+ 'tpl': 'jurko {zbojnik}',
+ 'fnc': function() {return 2},
+ 'prev' : 'Prev',
+ 'next' : 'Next',
+ 'from' : 'From',
+ 'to' : 'To',
+ 'l_quote' : '\u201C',
+ 'r_quote' : '\u201D'
+ }
+};
9 tests/refinerycms/refinerycms_test.js
View
@@ -48,6 +48,15 @@
Assert.isObject(cms.test);
},
+ testTranslations : function () {
+ var Assert = YUITest.Assert;
+
+
+ Assert.areEqual(cms.translate('prev'), 'Prev');
+ Assert.areEqual(cms.translate('fnc'), 2);
+ Assert.areEqual('jurko janosik', cms.translate('tpl', 'janosik'));
+ },
+
testExtend : function () {
var Assert = YUITest.Assert;
Please sign in to comment.
Something went wrong with that request. Please try again.