From 3a2a00db22907f98cc48479ddbee3096e717a750 Mon Sep 17 00:00:00 2001 From: Nathan Sollenberger <nathan@spacenate.com> Date: Thu, 9 Jul 2015 18:42:16 -0600 Subject: [PATCH] Refactor _addEditGoal.twig and _listGoalEdit.twig, remove duplicate files _viewGoal.twig and _listGoalView.twig --- plugins/Goals/templates/_listGoalEdit.twig | 30 +++++++----- plugins/Goals/templates/_listGoalView.twig | 57 ---------------------- plugins/Goals/templates/_viewGoal.twig | 53 -------------------- plugins/Goals/templates/editGoals.twig | 2 +- 4 files changed, 18 insertions(+), 124 deletions(-) delete mode 100644 plugins/Goals/templates/_listGoalView.twig delete mode 100644 plugins/Goals/templates/_viewGoal.twig diff --git a/plugins/Goals/templates/_listGoalEdit.twig b/plugins/Goals/templates/_listGoalEdit.twig index 2d8a87ca41..3275bbc393 100644 --- a/plugins/Goals/templates/_listGoalEdit.twig +++ b/plugins/Goals/templates/_listGoalEdit.twig @@ -6,8 +6,10 @@ <th>{{ 'Goals_GoalName'|translate }}</th> <th>{{ 'Goals_GoalIsTriggeredWhen'|translate }}</th> <th>{{ 'General_ColumnRevenue'|translate }}</th> - <th>{{ 'General_Edit'|translate }}</th> - <th>{{ 'General_Delete'|translate }}</th> + {% if userCanEditGoals %} + <th>{{ 'General_Edit'|translate }}</th> + <th>{{ 'General_Delete'|translate }}</th> + {% endif %} </tr> </thead> {% if goals is empty %} @@ -32,22 +34,24 @@ <td class="text-center"> {% if goal.revenue==0 %}-{% else %}{{ goal.revenue|money(idSite)|raw }}{% endif %} </td> - <td class="text-center"> - <button id="{{ goal.idgoal }}" class="edit-goal btn btn-flat btn-lg" title="{{ 'General_Edit'|translate }}"> - <span class="icon-edit"></span> - </button> - </td> - <td class="text-center"> - <button id="{{ goal.idgoal }}" class="delete-goal btn btn-flat btn-lg" title="{{ 'General_Delete'|translate }}"> - <span class="icon-delete"></span> - </button> - </td> + {% if userCanEditGoals %} + <td class="text-center"> + <button id="{{ goal.idgoal }}" class="edit-goal btn btn-flat btn-lg" title="{{ 'General_Edit'|translate }}"> + <span class="icon-edit"></span> + </button> + </td> + <td class="text-center"> + <button id="{{ goal.idgoal }}" class="delete-goal btn btn-flat btn-lg" title="{{ 'General_Delete'|translate }}"> + <span class="icon-delete"></span> + </button> + </td> + {% endif %} </tr> {% endfor %} {% endif %} </table> - {% if onlyShowAddNewGoal is not defined %} + {% if userCanEditGoals and onlyShowAddNewGoal is not defined %} <p> <button id="add-goal" class="btn btn-lg btn-flat"> <span class="icon-add"></span> diff --git a/plugins/Goals/templates/_listGoalView.twig b/plugins/Goals/templates/_listGoalView.twig deleted file mode 100644 index f8ef672877..0000000000 --- a/plugins/Goals/templates/_listGoalView.twig +++ /dev/null @@ -1,57 +0,0 @@ -<div id='entityEditContainer' class="managegoals" style="display:none;"> - <table class="dataTable entityTable"> - <thead> - <tr> - <th class="first">Id</th> - <th>{{ 'Goals_GoalName'|translate }}</th> - <th>{{ 'Goals_GoalIsTriggeredWhen'|translate }}</th> - <th>{{ 'General_ColumnRevenue'|translate }}</th> - </tr> - </thead> - {% if goals is empty %} - <tr> - <td colspan='7'> - <br/> - {{ 'Goals_ThereIsNoGoalToManage'|translate(siteName)|raw }}. - <br/><br/> - </td> - </tr> - {% else %} - {% for goal in goals %} - <tr> - <td class="first">{{ goal.idgoal }}</td> - <td>{{ goal.name|raw }}</td>{# NOTE: goal names are escaped in the DB #} - <td><span class='matchAttribute'>{{ goal.match_attribute }}</span> - {% if goal.pattern_type is defined %} - <br/> - {{ 'Goals_Pattern'|translate }} {{ goal.pattern_type }}: {{ goal.pattern|raw }} - {% endif %} - </td> - <td>{% if goal.revenue==0 %}-{% else %}{{ goal.revenue|money(idSite)|raw }}{% endif %}</td> - </tr> - {% endfor %} - {% endif %} - </table> -</div> - -<script type="text/javascript"> - var goalTypeToTranslation = { - "manually": "{{ 'Goals_ManuallyTriggeredUsingJavascriptFunction'|translate }}", - "file": "{{ 'Goals_Download'|translate }}", - "url": "{{ 'Goals_VisitUrl'|translate }}", - "title": "{{ 'Goals_VisitPageTitle'|translate }}", - "external_website": "{{ 'Goals_ClickOutlink'|translate }}", - "event_action": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventAction'|translate }})", - "event_category": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventCategory'|translate }})", - "event_name": "{{ 'Goals_SendEvent'|translate }} ({{ 'Events_EventName'|translate }})" - }; - - $(document).ready(function () { - // translation of the goal "match attribute" to human readable description - $('.matchAttribute').each(function () { - var matchAttribute = $(this).text(); - var translation = goalTypeToTranslation[matchAttribute]; - $(this).text(translation); - }); - }); -</script> diff --git a/plugins/Goals/templates/_viewGoal.twig b/plugins/Goals/templates/_viewGoal.twig deleted file mode 100644 index 40c7323b95..0000000000 --- a/plugins/Goals/templates/_viewGoal.twig +++ /dev/null @@ -1,53 +0,0 @@ - -{% import 'ajaxMacros.twig' as ajax %} -{{ ajax.errorDiv() }} -{{ ajax.loadingDiv('goalAjaxLoading') }} - -<div class="entityContainer"> - {% if onlyShowAddNewGoal is not defined %} - {% include "@Goals/_listGoalView.twig" %} - {% endif %} - <a id='bottom'></a> -</div> - -<script type="text/javascript"> - var mappingMatchTypeName = { - "url": "{{ 'Goals_URL'|translate }}", - "title": "{{ 'Goals_PageTitle'|translate }}", - "file": "{{ 'Goals_Filename'|translate }}", - "external_website": "{{ 'Goals_ExternalWebsiteUrl'|translate }}", - "event": "{{ 'Events_Event'|translate }}" - }; - var mappingMatchTypeExamples = { - "url": "{{ 'General_ForExampleShort'|translate }} {{ 'Goals_Contains'|translate("'checkout/confirmation'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_IsExactly'|translate("'http://example.com/thank-you.html'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_MatchesExpression'|translate("'(.*)\\\/demo\\\/(.*)'") }}", - "title": "{{ 'General_ForExampleShort'|translate }} {{ 'Goals_Contains'|translate("'Order confirmation'") }}", - "file": "{{ 'General_ForExampleShort'|translate }} {{ 'Goals_Contains'|translate("'files/brochure.pdf'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_IsExactly'|translate("'http://example.com/files/brochure.pdf'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_MatchesExpression'|translate("'(.*)\\\.zip'") }}", - "external_website": "{{ 'General_ForExampleShort'|translate }} {{ 'Goals_Contains'|translate("'amazon.com'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_IsExactly'|translate("'http://mypartner.com/landing.html'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_MatchesExpression'|translate("'http://www.amazon.com\\\/(.*)\\\/yourAffiliateId'") }}", - "event": "{{ 'General_ForExampleShort'|translate }} {{ 'Goals_Contains'|translate("'video'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_IsExactly'|translate("'click'") }} \ - <br />{{ 'General_ForExampleShort'|translate }} {{ 'Goals_MatchesExpression'|translate("'(.*)_banner'") }}" - }; - $(document).ready(function () { - bindGoalForm(); - - {% if onlyShowAddNewGoal is not defined %} - piwik.goals = {{ goalsJSON|raw }}; - bindListGoalEdit(); - - {% if idGoal %} - editGoal({{ idGoal|e('js') }}); - {% else %} - showEditGoals(); - {% endif %} - {% else %} - initAndShowAddGoalForm(); - {% endif %} - }); - -</script> diff --git a/plugins/Goals/templates/editGoals.twig b/plugins/Goals/templates/editGoals.twig index 63943ca432..76b64b9918 100644 --- a/plugins/Goals/templates/editGoals.twig +++ b/plugins/Goals/templates/editGoals.twig @@ -11,6 +11,6 @@ {{ 'Goals_NeedAccess'|translate|raw }} </p> - {% include "@Goals/_viewGoal.twig" %} + {% include "@Goals/_addEditGoal.twig" %} {% endif %} -- GitLab