Skip to content

Commit

Permalink
mod_survey now uses blocks instead of its own 'survey' data structure…
Browse files Browse the repository at this point in the history
…. Added pluggable blocks to the mod_admin. Added z_html:escape/2 for easy z_trans selection in combination with escape. Fixed issue in z_validation when the name was a binary.
  • Loading branch information
mworrell committed Jul 11, 2012
1 parent 450f2ac commit 52072eb
Show file tree
Hide file tree
Showing 77 changed files with 1,565 additions and 1,693 deletions.
6 changes: 6 additions & 0 deletions include/zotonic_notifications.hrl
Expand Up @@ -103,6 +103,11 @@
%% @doc Rewrite an url before it will be dispatched using the z_dispatcher (foldl)
-record(dispatch_rewrite, {is_dir=false, path=""}).

%% @doc Used in the admin to fetch the possible blocks for display (foldl)
-record(admin_edit_blocks, {id}).

%% Used for fetching the menu in the admin (foldl)
% admin_menu

%% @doc An activity in Zotonic. When this is handled as a notification then return a list
%% of patterns matching this activity. These patterns are then used to find interested
Expand Down Expand Up @@ -224,6 +229,7 @@

%% @doc Check if an action is allowed (first).
%% Should return undefined, true or false.
%% action :: view|update|delete
-record(acl_is_allowed, {action, object}).

%% @doc Check if an action on a property is allowed (first).
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_admin/lib/css/bootstrap-admin.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions modules/mod_admin/lib/css/zotonic-admin.css
Expand Up @@ -364,6 +364,14 @@ ul.blocks .ui-sortable-placeholder {
visibility: visible !important;
}

.input.inline {
display:inline-block;
padding-top:5px;
margin-bottom:0;
vertical-align:sub;
}


/* Connections
---------------------------------------------------------- */
ul.connections-list {
Expand Down
14 changes: 13 additions & 1 deletion modules/mod_admin/mod_admin.erl
Expand Up @@ -29,6 +29,7 @@
-export([
observe_sanitize_element/3,
observe_admin_menu/3,
observe_admin_edit_blocks/3,
event/2
]).

Expand Down Expand Up @@ -122,6 +123,16 @@ observe_admin_menu(admin_menu, Acc, Context) ->
|Acc].


observe_admin_edit_blocks(#admin_edit_blocks{}, Menu, Context) ->
[
{1, ?__("Texts", Context), [
{header, ?__("Header", Context)},
{text, ?__("Text", Context)}
]}
| Menu
].


event(#postback_notify{message="admin-insert-block"}, Context) ->
Language = case z_context:get_q("language", Context) of
undefined ->
Expand Down Expand Up @@ -149,7 +160,8 @@ event(#postback_notify{message="admin-insert-block"}, Context) ->
{edit_language, EditLanguage},
is_new,
{is_editable, z_acl:rsc_editable(RscId, Context)},
{blk, [{type, Type}]}
{blk, [{type, Type}]},
{blocks, lists:sort(z_notifier:foldl(#admin_edit_blocks{id=RscId}, [], Context))}
]
},
case z_html:escape(z_context:get_q("after", Context)) of
Expand Down
5 changes: 4 additions & 1 deletion modules/mod_admin/resources/resource_admin_edit.erl
Expand Up @@ -44,8 +44,11 @@ resource_exists(ReqData, Context) ->


html(Context) ->
Id = z_context:get(id, Context),
Blocks = z_notifier:foldl(#admin_edit_blocks{id=Id}, [], Context),
Vars = [
{id, z_context:get(id, Context)}
{id, Id},
{blocks, lists:sort(Blocks)}
],
Html = z_template:render({cat, "admin_edit.tpl"}, Vars, Context),
z_context:output(Html, Context).
Expand Down
13 changes: 9 additions & 4 deletions modules/mod_admin/templates/_admin_edit_block_addblock.tpl
Expand Up @@ -4,10 +4,15 @@
{_ + add block _}
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#" data-block-type="header">{_ Header _}</li></a>
<li><a href="#" data-block-type="text">{_ Text _}</li></a>
{# <li><a href="#" data-block-type="media">{_ Media _}</li></a> #}
<ul class="dropdown-menu nav-list nav">
{% for _order, title, items in blocks %}
{% if title %}
<li class="nav-header">{{ title }}</li>
{% endif %}
{% for type, title in items %}
<li><a href="#" data-block-type="{{ type }}">{{ title }}</li></a>
{% endfor %}
{% endfor %}
</ul>
</div>
{% endif %}
16 changes: 9 additions & 7 deletions modules/mod_admin/templates/_admin_edit_block_li.tpl
Expand Up @@ -3,16 +3,12 @@
<h3 class="widget-header">
<i title="{_ Drag to change position _}" class="icon-move"></i>
<span title="{_ Disconnect _}" class="icon-remove"></span>
<span>{{ blk.type|make_list|capfirst }} {_ block _}</span>
<input type="text" class="block-name" name="block-{{#s}}-name" id="block-{{#s}}-name" value="{{ blk.name|escape }}" title="{_ Block name _}" />
<span>{{ blk.type|make_list|capfirst|replace:"_":" " }} {_ block _}</span>
<input type="text" class="block-name" name="block-{{#s}}-name" id="block-{{#s}}-name" value="{{ blk.name|escape }}" title="{_ Block name _}" placeholder="{_ name _}" />
</h3>
<div class="widget-content">
<input type="hidden" name="block-{{#s}}-type" value="{{ blk.type }}" />
{% if blk.type == 'text' or not blk %}
{% include "_admin_edit_block_li_text.tpl" name=#s %}
{% elseif blk.type == 'header' %}
{% include "_admin_edit_block_li_header.tpl" name=#s %}
{% endif %}
{% include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}
</div>
{% if is_new %}
{% javascript %}
Expand All @@ -23,3 +19,9 @@
{% include "_admin_edit_block_addblock.tpl" %}
</li>
{% endwith %}

{% if is_new %}
{% javascript %}
$("#{{ #block }} .widget").effect("highlight");
{% endjavascript %}
{% endif %}
3 changes: 3 additions & 0 deletions modules/mod_admin/templates/admin_edit_widget_i18n.tpl
Expand Up @@ -19,6 +19,9 @@
{% endwith %}
{% endfor %}
</div>
<div class="tab-content widget-content">
{% block widget_content_nolang %}{% endblock %}
</div>
</div>
{% block widget_after %}{% endblock %}

Expand Down
2 changes: 2 additions & 0 deletions modules/mod_admin/templates/admin_edit_widget_std.tpl
Expand Up @@ -3,11 +3,13 @@
{% block widget_before %}{% endblock %}

<div id="{% block widget_id %}{% endblock %}" class="{% if in_dialog %}dialog-{% endif %}widget {% block widget_class %}{% endblock %} do_adminwidget" data-adminwidget="minifiedOnInit: {% block widget_show_minimized %}false{% endblock %}">
{% block widget_header %}
{% if not in_dialog %}
<h3 class="widget-header">
{% block widget_title %}{% endblock %}
</h3>
{% endif %}
{% endblock %}
<div class="widget-content">
{% block widget_content %}{% endblock %}
</div>
Expand Down
19 changes: 14 additions & 5 deletions modules/mod_base/filters/filter_replace.erl
Expand Up @@ -17,12 +17,21 @@
%% limitations under the License.

-module(filter_replace).
-export([replace/3]).
-export([
replace/3,
replace/4
]).


replace(undefined, _, _Context) ->
undefined;
replace(In, [A,B], _Context) when is_binary(A) orelse is_list(A) ->
iolist_to_binary(re:replace(In, A, B, [global]));
replace(In, A, _Context) ->
iolist_to_binary(re:replace(In, A, [], [global])).
replace(In, [A,B], Context) when is_binary(A) orelse is_list(A) ->
replace(In, A, B, Context);
replace(In, A, Context) ->
replace(In, A, <<>>, Context).

replace(In, A, B, Context) ->
In1 = z_trans:lookup_fallback(In, Context),
A1 = z_trans:lookup_fallback(A, Context),
B1 = z_trans:lookup_fallback(B, Context),
iolist_to_binary(re:replace(In1, A1, B1, [global])).
6 changes: 1 addition & 5 deletions modules/mod_base_site/templates/text/_blocks.tpl
@@ -1,7 +1,3 @@
{% for blk in m.rsc[id].blocks %}
{% if blk.type == 'header' %}
<h2 class="block-header" {% if blk.name %}id="{{ blk.name }}"{% endif %}>{{ blk.header }}</h2>
{% elseif blk.body %}
<div class="block-text">{{ blk.body|show_media }}</div>
{% endif %}
{% include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% endfor %}
@@ -0,0 +1 @@
<h2 class="block-header" {% if blk.name %}id="{{ blk.name }}"{% endif %}>{{ blk.header }}</h2>
@@ -0,0 +1 @@
<div class="block-text">{{ blk.body|show_media }}</div>

This file was deleted.

This file was deleted.

0 comments on commit 52072eb

Please sign in to comment.