Skip to content

Commit

Permalink
Merge pull request django-cms#880 from FinalAngel/feature/toolbar-fro…
Browse files Browse the repository at this point in the history
…ntend

Feature/toolbar frontend
  • Loading branch information
ojii committed Jun 19, 2011
2 parents 5285d2f + 0a8eafd commit 51a0b95
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 48 deletions.
1 change: 1 addition & 0 deletions cms/media/cms/css/plugins/cms.toolbar.css
Expand Up @@ -104,6 +104,7 @@
.cms_toolbar-item_list li:only-child a { -webkit-border-radius:4px; -moz-border-radius:4px; border-radius:4px; }
.cms_toolbar-item_list li.active a { background:#ddd; }

.cms_toolbar-item_list .cms_toolbar-item_admin { padding-top:0 !important; }

/* #TOOLBAR/list/icons# */
.cms_toolbar-item_list .cms_toolbar_icon { width:18px; margin-right:4px; background-position:left 1px; }
Expand Down
15 changes: 12 additions & 3 deletions cms/media/cms/js/change_list.js
Expand Up @@ -331,13 +331,22 @@

if(action=="copy"){
//url = insert_into_url(url, "copy", selected_page);
url = CMS.Helpers.setUrl(CMS.Helpers.getUrl(document.location), "copy=" + selected_page + "", "copy");
url = CMS.API.Helpers.setUrl(document.location, {
'addParam': "copy=" + selected_page,
'removeParam': "copy"
});
}else{
//url = remove_from_url(url, "copy");
url = CMS.Helpers.setUrl(CMS.Helpers.getUrl(document.location), "copy", "copy");
url = CMS.API.Helpers.setUrl(document.location, {
'addParam': "copy",
'removeParam': "copy"
});
}
//url = insert_into_url(url, "site__exact", id);
url = CMS.Helpers.setUrl(CMS.Helpers.getUrl(document.location), "site__exact=" + id + "", "site__exact");
url = CMS.API.Helpers.setUrl(document.location, {
'addParam': "site__exact=" + id,
'removeParam': "site__exact"
});

window.location = url;
});
Expand Down
3 changes: 0 additions & 3 deletions cms/media/cms/js/libs/classy.min.js
Expand Up @@ -13,9 +13,6 @@ if(window['console'] === undefined) {
log = console.debug || console.log || alert;
}

/* initiate classy namespace */
var CMS = CMS || {};

/* initialize classy */
(function() {
var CLASSY_VERSION = '1.3.1',
Expand Down
36 changes: 23 additions & 13 deletions cms/media/cms/js/plugins/cms.base.js
Expand Up @@ -6,19 +6,20 @@
* assign Class and CMS namespace */
var CMS = CMS || {};
CMS.Class = CMS.Class || Class.$noConflict();
CMS.API = CMS.API || {};

(function ($) {
/*##################################################|*/
/* #CMS.BASE# */
jQuery(document).ready(function ($) {
/**
* Security
* @version: 0.1.1
* @version: 1.0.0
* @description: Adds security layer to CMS namespace
* @public_methods:
* - CMS.Security.csrf();
* - CMS.API.Security.csrf();
*/
CMS.Security = {
CMS.API.Security = {

csrf: function () {
$.ajaxSetup({
Expand Down Expand Up @@ -51,20 +52,21 @@ jQuery(document).ready(function ($) {
}
}
});
return 'ready';
}

};

/**
* Helpers
* @version: 0.1.1
* @version: 1.0.0
* @description: Adds helper methods to be invoked
* @public_methods:
* - CMS.Helpers.reloadBrowser();
* - CMS.Helpers.getUrl(str);
* - CMS.Helpers.setUrl(getUrlObj, addParam, removeParam);
* - CMS.API.Helpers.reloadBrowser();
* - CMS.API.Helpers.getUrl(urlString);
* - CMS.API.Helpers.setUrl(urlString, options);
*/
CMS.Helpers = {
CMS.API.Helpers = {

reloadBrowser: function () {
window.location.reload();
Expand Down Expand Up @@ -93,15 +95,19 @@ jQuery(document).ready(function ($) {
return uri;
},

setUrl: function (getUrlObj, addParam, removeParam) {
setUrl: function (str, options) {
var uri = str;

// now we neet to get the partials of the element
var getUrlObj = this.getUrl(uri);
var query = getUrlObj.queryKey;
var serialized = '';
var index = 0;

// we could loop the query and replace the param at the right place
// but instead of replacing it just append it to the end of the query so its more visible
delete query[removeParam];
query[addParam.split('=')[0]] = addParam.split('=')[1];
if(options && options.removeParam) delete query[options.removeParam];
if(options && options.addParam) query[options.addParam.split('=')[0]] = options.addParam.split('=')[1];

$.each(query, function (key, value) {
// add &
Expand All @@ -111,7 +117,11 @@ jQuery(document).ready(function ($) {
index++;
});

uri = getUrlObj.directory + '?' + serialized;
// check if we should add the questionmark
var addition = (serialized === '') ? '' : '?';
var anchor = (getUrlObj.anchor) ? '#' + getUrlObj.anchor : '';

uri = getUrlObj.protocol + '://' + getUrlObj.authority + getUrlObj.directory + getUrlObj.file + addition + serialized + anchor;

return uri;
}
Expand All @@ -120,4 +130,4 @@ jQuery(document).ready(function ($) {

});

})(jQuery);
})(jQuery);
23 changes: 12 additions & 11 deletions cms/media/cms/js/plugins/cms.placeholders.js
Expand Up @@ -10,14 +10,14 @@
jQuery(document).ready(function ($) {
/**
* Placeholders
* @version: 0.1.2
* @version: 1.0.0
* @description: Handles placeholders when in editmode and adds "lightbox" to toolbar
* @public_methods:
* - CMS.Placeholder.addPlugin(url, obj);
* - CMS.Placeholder.editPlugin(placeholder_id, plugin_id);
* - CMS.Placeholder.deletePlugin(placeholder_id, plugin_id, plugin);
* - CMS.Placeholder.toggleFrame();
* - CMS.Placeholder.toggleDim();
* - CMS.API.Placeholder.addPlugin(url, obj);
* - CMS.API.Placeholder.editPlugin(placeholder_id, plugin_id);
* - CMS.API.Placeholder.deletePlugin(placeholder_id, plugin_id, plugin);
* - CMS.API.Placeholder.toggleFrame();
* - CMS.API.Placeholder.toggleDim();
* @compatibility: IE >= 6, FF >= 2, Safari >= 4, Chrome > =4, Opera >= 10
*/
CMS.Placeholders = CMS.Class.$extend({
Expand Down Expand Up @@ -201,7 +201,7 @@ jQuery(document).ready(function ($) {
that.editPlugin.call(that, data.placeholder_id, response);
},
'error': function () {
log('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
throw new Error('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
}
});
},
Expand Down Expand Up @@ -275,7 +275,7 @@ jQuery(document).ready(function ($) {
plugin.remove();
},
'error': function () {
log('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
throw new Error('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
}
});
}
Expand Down Expand Up @@ -322,7 +322,7 @@ jQuery(document).ready(function ($) {
'data': { 'ids': array.join('_') },
'success': refreshPluginPosition,
'error': function () {
log('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
throw new Error('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
}
});

Expand Down Expand Up @@ -399,7 +399,7 @@ jQuery(document).ready(function ($) {
refreshPluginPosition(slot);
},
'error': function () {
log('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
throw new Error('CMS.Placeholders was unable to perform this ajax request. Try again or contact the developers.');
}
});
});
Expand Down Expand Up @@ -455,6 +455,7 @@ jQuery(document).ready(function ($) {

_showPluginList: function (el) {
// save reference to this class
// TODO: make sure the element is really shown over everything
var that = this;
var list = el.parent().find('.cms_placeholder-subnav');
list.show();
Expand Down Expand Up @@ -501,7 +502,7 @@ jQuery(document).ready(function ($) {
// frame should always have space on top
this.frame.css('top', pos+offset);
// make sure that toolbar is visible
if(this.toolbar.data('collapsed')) CMS.Toolbar._showToolbar();
if(this.toolbar.data('collapsed')) CMS.Toolbar.API._showToolbar();
// listen to toolbar events
this.toolbar.bind('cms.toolbar.show cms.toolbar.hide', function (e) {
(e.handleObj.namespace === 'show.toolbar') ? that.frame.css('top', pos+offset) : that.frame.css('top', pos);
Expand Down
39 changes: 26 additions & 13 deletions cms/media/cms/js/plugins/cms.toolbar.js
Expand Up @@ -11,20 +11,21 @@ jQuery(document).ready(function ($) {

/**
* Toolbar
* @version: 0.1.2
* @version: 1.0.0
* @description: Implements and controls toolbar
* @public_methods:
* - CMS.Toolbar.toggleToolbar();
* - CMS.Toolbar.registerItem(obj);
* - CMS.Toolbar.registerItems(array);
* - CMS.Toolbar.removeItem(id);
* - CMS.Toolbar.registerType(function);
* - CMS.API.Toolbar.toggleToolbar();
* - CMS.API.Toolbar.registerItem(obj);
* - CMS.API.Toolbar.registerItems(array);
* - CMS.API.Toolbar.removeItem(id);
* - CMS.API.Toolbar.registerType(function);
* @compatibility: IE >= 6, FF >= 2, Safari >= 4, Chrome > =4, Opera >= 10
* TODO: login needs special treatment (errors, login on enter)
* TODO: styling of the collapser button needs to be somehow transparent
*/
CMS.Toolbar = CMS.Class.$extend({

implement: [CMS.Helpers, CMS.Security],
implement: [CMS.API.Helpers, CMS.API.Security],

options: {
'debug': false, // not integrated yet
Expand All @@ -35,7 +36,7 @@ jQuery(document).ready(function ($) {
// save reference to this class
var that = this;
// check if only one element is given
if($(container).length > 2) { log('Toolbar Error: one element expected, multiple elements given.'); return false; }
if($(container).length > 2) { throw new Error('Toolbar Error: one element expected, multiple elements given.'); return false; }
// merge passed argument options with internal options
this.options = $.extend(this.options, options);

Expand Down Expand Up @@ -86,7 +87,7 @@ jQuery(document).ready(function ($) {
toggleToolbar: function () {
(this.toolbar.data('collapsed')) ? this._showToolbar() : this._hideToolbar();

return this;
return this.toolbar.data('collapsed');
},

_showToolbar: function () {
Expand All @@ -103,6 +104,8 @@ jQuery(document).ready(function ($) {
$.cookie('CMS_toolbar-collapsed', false, { path:'/', expires:7 });
// add show event to toolbar
this.toolbar.trigger('cms.toolbar.show');

return this.toolbar.data('collapsed');
},

_hideToolbar: function () {
Expand All @@ -119,10 +122,13 @@ jQuery(document).ready(function ($) {
$.cookie('CMS_toolbar-collapsed', true, { path:'/', expires:7 });
// add hide event to toolbar
this.toolbar.trigger('cms.toolbar.hide');

return this.toolbar.data('collapsed');
},

registerItem: function (obj) {
// error handling
if(typeof(obj) != 'object') return false;
if(!obj.order) obj.dir = 0;

// check for internal types
Expand Down Expand Up @@ -214,12 +220,18 @@ jQuery(document).ready(function ($) {
if(btn.data('state')) {
btn.stop().animate({'backgroundPosition': '-40px -198px'}, function () {
// disable link
document.location = that.setUrl(that.getUrl(document.location), obj.removeParameter, obj.addParameter);
document.location = that.setUrl(document.location, {
'addParam': obj.removeParameter,
'removeParam': obj.addParameter
});
});
} else {
btn.stop().animate({'backgroundPosition': '0px -198px'}, function () {
// enable link
document.location = that.setUrl(that.getUrl(document.location), obj.addParameter, obj.removeParameter);
document.location = that.setUrl(document.location, {
'addParam': obj.addParameter,
'removeParam': obj.removeParameter
});
});
}
});
Expand Down Expand Up @@ -248,6 +260,7 @@ jQuery(document).ready(function ($) {
// add icon if available
var icon = (value.icon !== '') ? 'cms_toolbar_icon cms_toolbar_icon-enabled ' : '';
// replace attributes
// TODO: instead of using value.class use value.cls
tmp += list.replace('[list_title]', value.title)
.replace('[list_url]', value.url)
.replace('[list_method]', value.method)
Expand Down Expand Up @@ -280,10 +293,10 @@ jQuery(document).ready(function ($) {
'url': $(e.currentTarget).attr('href'),
'data': $(e.currentTarget).attr('href').split('?')[1],
'success': function () {
CMS.Helpers.reloadBrowser();
CMS.API.Helpers.reloadBrowser();
},
'error': function () {
log('CMS.Toolbar was unable to perform this ajax request. Try again or contact the developers.');
throw new Error('CMS.Toolbar was unable to perform this ajax request. Try again or contact the developers.');
}
});
// after clicking hide list
Expand Down
Expand Up @@ -10,7 +10,7 @@
<script type="text/javascript">
jQuery(document).ready(function ($) {
// initialize security patch
CMS.Security.csrf();
CMS.API.Security.csrf();
});
</script>
{% endblock %}
2 changes: 1 addition & 1 deletion cms/templates/admin/cms/page/plugin_forms_ok.html
Expand Up @@ -16,7 +16,7 @@
jQuery(document).ready(function ($) {
// if it is an iframe
if(window.parent != self) {
setTimeout(function () { window.parent.CMS.Helpers.reloadBrowser(); }, 1000);
setTimeout(function () { window.parent.CMS.API.Helpers.reloadBrowser(); }, 1000);
} else {
opener.dismissEditPluginPopup(window, "{{ plugin_id }}", "{{ icon }}", "{{ alt }}");
}
Expand Down
6 changes: 3 additions & 3 deletions cms/templates/cms/toolbar/toolbar.html
Expand Up @@ -12,10 +12,10 @@
//<![CDATA[
jQuery(document).ready(function ($) {
// initialize toolbar, pass options, items and allow public access
CMS.Toolbar = new CMS.Toolbar('#cms_toolbar', {{ CMS_TOOLBAR_CONFIG|safe }});
CMS.API.Toolbar = new CMS.Toolbar('#cms_toolbar', {{ CMS_TOOLBAR_CONFIG|safe }});

// initialize placeholders, pass options and keep it private
CMS.Placeholders = new CMS.Placeholders('#cms_toolbar', {
CMS.API.Placeholders = new CMS.Placeholders('#cms_toolbar', {
{% if request.toolbar.edit_mode %}'edit_mode': true,{% endif %}
'urls': {
'cms_page_move_plugin': '{% url admin:cms_page_move_plugin %}',
Expand Down Expand Up @@ -89,4 +89,4 @@

<!-- item: html - login -->
{% include "cms/toolbar/items/login.html" %}
</div>
</div>

0 comments on commit 51a0b95

Please sign in to comment.