Skip to content

Commit

Permalink
Merge branch 'master' into acl-content-groups
Browse files Browse the repository at this point in the history
  • Loading branch information
mworrell committed Apr 14, 2015
2 parents 385d7cc + f165df0 commit bcc72cb
Show file tree
Hide file tree
Showing 22 changed files with 142 additions and 50 deletions.
2 changes: 1 addition & 1 deletion modules/mod_admin/templates/_admin_edit_block_li.tpl
Expand Up @@ -8,7 +8,7 @@
<div class="widget-content">
<input type="text" class="form-control block-name" name="block-{{#s}}-name" id="block-{{#s}}-name" value="{{ blk.name|escape }}" title="{_ Block name _}" placeholder="{_ name _}" />
<input type="hidden" class="block-type" name="block-{{#s}}-type" value="{{ blk.type }}" />
{% include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}
{% optional 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>
</div>
{% if is_new %}
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_base/lib/js/apps/zotonic-1.0.js
Expand Up @@ -1858,7 +1858,7 @@ function ensure_name_value(a)
}

// Update the contents of an iframe
function z_iframe_update(name, doc)
function z_update_iframe(name, doc)
{
var iframe = window.frames[name];
if (iframe) {
Expand Down
12 changes: 11 additions & 1 deletion modules/mod_base/scomps/scomp_base_include.erl
Expand Up @@ -47,7 +47,17 @@ render(Params, Vars, Context) ->

case proplists:get_value('$all', Params, false) of
false ->
{ok, z_template:render(File, Vars1, Context1)};
try
{ok, z_template:render(File, Vars1, Context1)}
catch
throw:{error, {template_not_found, _File, _Reason}} = NotFound ->
case proplists:get_value('$optional', Params) of
true ->
{ok, <<>>};
_ ->
throw(NotFound)
end
end;
true ->
Templates = z_template:find_template(File, true, Context1),
{ok, [ z_template:render(Tpl, Vars1, Context1) || Tpl <- Templates ]}
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_base_site/templates/text/_blocks.tpl
@@ -1,3 +1,3 @@
{% for blk in m.rsc[id].blocks %}
{% include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% optional include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% endfor %}
25 changes: 20 additions & 5 deletions modules/mod_import_csv/mod_import_csv.erl
Expand Up @@ -161,8 +161,9 @@ inspect_file(Filename) ->
{ok, Device} ->
FSize = filelib:file_size(Filename),
case file:read(Device, min(4096,FSize)) of
{ok, Data} ->
{ok, Data0} ->
file:close(Device),
Data = utf8(Data0),
case fetch_column_defs(Data) of
{ok, Cols, Sep} ->
Cols1 = [ to_property_name(Col) || Col <- Cols ],
Expand All @@ -185,6 +186,18 @@ inspect_file(Filename) ->
Error
end.

utf8(S) ->
case z_string:sanitize_utf8(S) of
S ->
S;
Stripped ->
case eiconv:convert("Windows-1250", S) of
{ok, Utf8} -> Utf8;
{error, _} -> Stripped
end
end.


%% @doc Check if the first row is made up of column headers.
%% The file must have at least a name and a category column.
fetch_column_defs(<<>>) ->
Expand All @@ -194,10 +207,12 @@ fetch_column_defs(B) ->
{ok, Line} ->
{ok, Tabs} = parse_line(Line, $\t),
{ok, Comma} = parse_line(Line, $,),
{Cols, Sep} = case length(Tabs) > length(Comma) of
true -> {Tabs, $\t};
false -> {Comma, $,}
end,
{ok, SCol} = parse_line(Line, $;),
{_, Cols, Sep} = lists:last(lists:sort([
{length(Tabs), Tabs, $\t},
{length(Comma), Comma, $,},
{length(SCol), SCol, $;}
])),
{ok, [ z_convert:to_list(z_string:trim(C)) || C <- Cols ], Sep};
_ ->
{error, invalid_csv_file}
Expand Down
3 changes: 3 additions & 0 deletions modules/mod_survey/lib/css/survey.css
Expand Up @@ -40,3 +40,6 @@ form.z_form_invalid .alert.z_invalid {
display: block;
}

.form-survey .form-actions {
margin-top: 12px;
}
2 changes: 1 addition & 1 deletion modules/mod_survey/support/mod_survey_schema.erl
Expand Up @@ -69,7 +69,7 @@ install_survey_answer_table(Context) ->
#column_def{name=name, type="character varying", length=32, is_nullable=false},
#column_def{name=value, type="character varying", length=80, is_nullable=true},
#column_def{name=text, type="bytea", is_nullable=true},
#column_def{name=created, type="timestamp", is_nullable=true}
#column_def{name=created, type="timestamp with time zone", is_nullable=true}
], Context),

% Add some indices and foreign keys, ignore errors
Expand Down
4 changes: 4 additions & 0 deletions modules/mod_survey/templates/_admin_edit_content.survey.tpl
Expand Up @@ -14,6 +14,10 @@
<div class="row">
<div class="col-lg-6 col-md-6">
<div class="form-group">
<div class="checkbox"><label>
<input type="checkbox" name="survey_is_autostart" id="survey_is_autostart" value="1" {% if id.survey_is_autostart or (id.survey_is_autostart|is_undefined and id.is_a.poll) %}checked="checked"{% endif %} />
{_ Immediately start with the questions, no “Start” button _}
</label></div>
<div class="checkbox"><label>
{% if id.is_a.poll %}
<input type="hidden" name="survey_show_results" id="survey_show_results" value="1" />
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_survey/templates/_admin_survey_edit_block.tpl
@@ -1,5 +1,5 @@
<input type="hidden" class="block-type" name="block-{{#s}}-type" value="{{ blk.type|default:block_type }}" />
{% include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}
{% optional include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}

{% if is_new %}
{% javascript %}
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_survey/templates/_admin_survey_question_q.tpl
Expand Up @@ -8,7 +8,7 @@
<div class="block-options">
{% if blk and blk.type %}
<input type="hidden" class="block-type" name="block-{{#s}}-type" value="{{ blk.type }}" />
{% include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}
{% optional include ["blocks/_admin_edit_block_li_",blk.type,".tpl"]|join name=#s blk=blk id=id is_editable=is_editable is_new=is_new %}
{% endif %}
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions modules/mod_survey/templates/_survey_autostart_body.tpl
@@ -0,0 +1,11 @@
{% include "_meta.tpl" %}

{% include "_address.tpl" %}

{% block subnav %}
{% include "_subnav.tpl" %}
{% endblock %}

<div class="body">
{{ id.body }}
</div>
15 changes: 15 additions & 0 deletions modules/mod_survey/templates/_survey_autostart_footer.tpl
@@ -0,0 +1,15 @@
{% block seealso %}
{% include "_content_list.tpl" list=id.o.hasfeatured %}
{% include "_content_list.tpl" list=id.o.haspart in_collection=id %}
{% include "_content_list.tpl" list=id.o.relation %}
{% endblock %}

{% block thumbnails %}
{% include "_page_thumbnails.tpl" %}
{% endblock %}

{% block sidebar_collection %}
{% with m.rsc.sidebar_collection.id as id %}
{% include "_content_list.tpl" list=id.o.haspart %}
{% endwith %}
{% endblock %}
2 changes: 1 addition & 1 deletion modules/mod_survey/templates/_survey_end.tpl
@@ -1,6 +1,6 @@
{% with id.blocks['survey_feedback'] as blk %}
{% if blk and (blk.type /= 'text' or blk.body) %}
{% include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% optional include ["blocks/_block_view_",blk.type,".tpl"]|join blk=blk id=id %}
{% else %}
<h2>{_ Thank you _}</h2>

Expand Down
22 changes: 17 additions & 5 deletions modules/mod_survey/templates/_survey_question_page.tpl
@@ -1,4 +1,10 @@
{% block question_page %}
{% if page_nr == 1 and id.survey_is_autostart %}
{% block autostart_body %}
{% include "_survey_autostart_body.tpl" %}
{% endblock %}
{% endif %}

{% wire id=#q type="submit"
postback={survey_next id=id page_nr=page_nr answers=answers history=history element_id=element_id|default:"survey-question"}
delegate="mod_survey"
Expand All @@ -16,24 +22,24 @@
{% endif %}

{% for blk in questions %}
{% include ["blocks/_block_view_",blk.type,".tpl"]|join id=id blk=blk answers=answers nr=forloop.counter %}
{% optional include ["blocks/_block_view_",blk.type,".tpl"]|join id=id blk=blk answers=answers nr=forloop.counter %}
{% endfor %}
</fieldset>

<div class="alert alert-error z_invalid">
<div class="alert alert-warning z_invalid">
{_ Please fill in all the required fields. _}
</div>

<div class="form-actions">
{% if page_nr > 1 %}
<a id="{{ #back }}" href="#" class="btn">{_ Back _}</a>
<a id="{{ #back }}" href="#" class="btn btn-default">{_ Back _}</a>
{% wire id=#back
postback={survey_back id=id page_nr=page_nr answers=answers history=history element_id=element_id|default:"survey-question"}
delegate="mod_survey"
%}
{% endif %}
{% if not id.is_a.poll %}
<a id="{{ #cancel }}" href="#" class="btn">{_ Stop _}</a>
{% if not id.survey_autostart or page_nr > 1 %}
<a id="{{ #cancel }}" href="#" class="btn btn-default">{_ Stop _}</a>
{% wire id=#cancel action={confirm text=_"Are you sure you want to stop?" ok=_"Stop" cancel=_"Continue" action={redirect id=id}} %}
{% endif %}
{% with questions|last as last_q %}
Expand All @@ -51,6 +57,12 @@
$(window).scrollTop(pos+100);
}
{% endjavascript %}

{% if page_nr == 1 and id.survey_is_autostart %}
{% block autostart_footer %}
{% include "_survey_autostart_footer.tpl" %}
{% endblock %}
{% endif %}
{% endblock %}

{% block question_page_after %}
Expand Down
2 changes: 1 addition & 1 deletion modules/mod_survey/templates/_survey_results.tpl
Expand Up @@ -16,7 +16,7 @@
<div class="survey_result">
{% if not result %}
{#
{% include ["blocks/_block_view_",question.type,".tpl"]|join id=id blk=question answers=answers %}
{% optional include ["blocks/_block_view_",question.type,".tpl"]|join id=id blk=question answers=answers %}
#}
{% else %}
{% if chart.question %}
Expand Down
27 changes: 17 additions & 10 deletions modules/mod_survey/templates/_survey_start.tpl
@@ -1,14 +1,21 @@
<div class="buttons survey-start">
<button id="{{ #survey_next }}" class="btn btn-primary">{_ Start _}</button>
{% wire id=#survey_next
{% if id.survey_is_autostart %}
{% wire
postback={survey_start id=id answers=answers}
delegate="mod_survey"
%}
{% else %}
<div class="buttons survey-start">
<button id="{{ #survey_next }}" class="btn btn-primary">{_ Start _}</button>
{% wire id=#survey_next
postback={survey_start id=id answers=answers}
delegate="mod_survey"
%}

{% if id.survey_show_results %}
<button id="{{ #survey_result }}" class="btn btn-default">{_ Results _}</button>
{% wire id=#survey_result
action={redirect dispatch="survey_results" id=id}
%}
{% endif %}
</div>
{% if id.survey_show_results %}
<button id="{{ #survey_result }}" class="btn btn-default">{_ Results _}</button>
{% wire id=#survey_result
action={redirect dispatch="survey_results" id=id}
%}
{% endif %}
</div>
{% endif %}
4 changes: 3 additions & 1 deletion modules/mod_survey/templates/survey.tpl
Expand Up @@ -8,7 +8,9 @@
{% block content_attributes %}{% include "_language_attrs.tpl" id=id class="wrapper" %} id="survey-question"{% endblock %}

{% block body %}
{{ id.body|show_media }}
{% if not id.survey_is_autostart %}
{{ id.body|show_media }}
{% endif %}
{% endblock %}

{% block below_body %}
Expand Down
34 changes: 19 additions & 15 deletions src/erlydtl/erlydtl_compiler.erl
Expand Up @@ -1638,11 +1638,27 @@ resolve_value_ast(Value, Context, TreeWalker) ->


%% Added by Marc Worrell - handle evaluation of scomps by z_scomp
scomp_ast(ScompName, Args, false = _All, Context, TreeWalker) ->
scomp_ast(ScompName, Args, true, Context, TreeWalker) ->
{ArgsAst, TreeWalker1} = scomp_ast_list_args(Args, Context, TreeWalker),
AppAst = erl_syntax:application(
erl_syntax:atom(z_scomp),
erl_syntax:atom(render_all),
[ erl_syntax:atom(ScompName),
ArgsAst,
erl_syntax:variable("Variables"),
z_context_ast(Context)
]
),
{{AppAst, #ast_info{}}, TreeWalker1};
scomp_ast(ScompName, Args, All, Context, TreeWalker) ->
{ArgsAst, TreeWalker1} = scomp_ast_list_args(Args, Context, TreeWalker),
AppAst = erl_syntax:application(
erl_syntax:atom(z_scomp),
erl_syntax:atom(render),
erl_syntax:atom(
case All of
false -> render;
optional -> render_optional
end),
[ erl_syntax:atom(ScompName),
ArgsAst,
erl_syntax:variable("Variables"),
Expand All @@ -1669,19 +1685,7 @@ scomp_ast(ScompName, Args, false = _All, Context, TreeWalker) ->
none,
[ErrStrAst]),
CallAst = erl_syntax:case_expr(AppAst, [OkAst, ErrorAst]),
{{CallAst, #ast_info{}}, TreeWalker1};
scomp_ast(ScompName, Args, true, Context, TreeWalker) ->
{ArgsAst, TreeWalker1} = scomp_ast_list_args(Args, Context, TreeWalker),
AppAst = erl_syntax:application(
erl_syntax:atom(z_scomp),
erl_syntax:atom(render_all),
[ erl_syntax:atom(ScompName),
ArgsAst,
erl_syntax:variable("Variables"),
z_context_ast(Context)
]
),
{{AppAst, #ast_info{}}, TreeWalker1}.
{{CallAst, #ast_info{}}, TreeWalker1}.


scomp_ast_list_args(Args, Context, TreeWalker) ->
Expand Down
2 changes: 1 addition & 1 deletion src/support/z_render.erl
Expand Up @@ -304,7 +304,7 @@ appear_after(TargetId, Html, Context) ->
update_iframe(IFrameId, Html, Context) ->
{Html1, Context1} = render_html(Html, Context),
Update = [
<<"z_iframe_update('">>,IFrameId,
<<"z_update_iframe('">>,IFrameId,
<<"','">>, z_utils:js_escape(Html1), <<"');">>
],
Context1#context{updates=[{Update}|Context1#context.updates]}.
Expand Down
13 changes: 11 additions & 2 deletions src/support/z_scomp.erl
Expand Up @@ -22,7 +22,7 @@
-module(z_scomp).
-author("Marc Worrell <marc@worrell.nl>").

-export([render/4, render_all/4]).
-export([render/4, render_all/4, render_optional/4]).

-include_lib("zotonic.hrl").

Expand All @@ -36,7 +36,16 @@ render(ScompName, Args, Vars, Context) ->
render_scomp_module(ModuleName, Args, Vars, ScompContext, Context);
{error, enoent} ->
%% No such scomp, as we can switch on/off functionality we do a quiet skip
?LOG("No scomp enabled for \"~p\"", [ScompName]),
lager:info("No scomp enabled for \"~p\"", [ScompName]),
{ok, <<>>}
end.

render_optional(ScompName, Args, Vars, Context) ->
case z_module_indexer:find(scomp, ScompName, Context) of
{ok, #module_index{erlang_module=ModuleName}} ->
ScompContext = z_context:prune_for_scomp(z_acl:args_to_visible_for(Args), Context),
render_scomp_module(ModuleName, ['$optional'|Args], Vars, ScompContext, Context);
{error, enoent} ->
{ok, <<>>}
end.

Expand Down
2 changes: 1 addition & 1 deletion src/support/z_search.erl
Expand Up @@ -65,7 +65,7 @@ pager(#search_result{result=Result} = SearchResult, Page, PageLen, _Context) ->
false ->
[]
end,
Next = if Offset + PageLen < Total -> false; true -> Page+1 end,
Next = if Offset + PageLen < Total -> Page+1; true -> false end,
Prev = if Page > 1 -> Page-1; true -> 1 end,
SearchResult#search_result{
result=OnPage,
Expand Down
2 changes: 1 addition & 1 deletion src/support/z_template.erl
Expand Up @@ -92,7 +92,7 @@ render(File, Variables, Context) ->

maybe_render({ok, ModuleIndex}, File, Variables, Context) ->
render1(File, ModuleIndex, Variables, Context);
maybe_render({error, Reason}, File, _Variable, _Context) ->
maybe_render({error, Reason}, File, _Variables, _Context) ->
lager:info("Could not find template: ~s (~p)", [File, Reason]),
throw({error, {template_not_found, File, Reason}}).

Expand Down

0 comments on commit bcc72cb

Please sign in to comment.