_binary From 2380c3ca36642b2936823abf6de4ca5b15ad8a30 Mon Sep 17 00:00:00 2001
From: epinapala <epinapala@ebay.com>
Date: Mon, 20 Oct 2014 00:18:53 -0700
Subject: [PATCH] Back button changes

- Created a new Icon for back button.

- When the user navigates to the Wiki edit page from a help-open page, they will see the back button. Clicking on back button will navigate the user to the help-open page, with the help article open.

- Also the back button stays in place even if the user navigates from edit -> read page or edit > edit expanded page or edit -> edit expanded > read expanded etc cases that are possible for the user to navigate.
---
 controllers/controller.php          |  38 +++++++++++++++++++++++++++++
 css/search.css                      |   4 +++
 resources/back.png                  | Bin 0 -> 2034 bytes
 scripts/basic.js                    |  47 +++++++++++++++++++-----------------
 views/elements/wiki_element.php     |  27 +++++++++++++++++++++
 views/helpers/helpbutton_helper.php |  16 +++++++-----
 views/wiki_view.php                 |   3 +++
 7 files changed, 107 insertions(+), 28 deletions(-)
 create mode 100644 resources/back.png

diff --git a/controllers/controller.php b/controllers/controller.php
index f0a56a6..22177d4 100755
--- a/controllers/controller.php
+++ b/controllers/controller.php
@@ -255,9 +255,47 @@ abstract class Controller
             }
         }
         $data['c'] = isset($_REQUEST['c']) ? $_REQUEST['c'] : NULL;
+        $data = array_merge($data,$this->setupWikiHelpBackLogic());
         $this->view($view)->render($data);
     }
     /**
+     * This is a helper method that sets proper data vars required to perform
+     * Back page logic when the user is navigating from help article to edit
+     * page,and then back to help article.
+     * @param type $data to add data vars
+     * @return string $data
+     */
+    function setupWikiHelpBackLogic() {
+        $data =  array();
+        $data["OTHER_BACK_URL"] = "";
+        if(isset($_REQUEST['back_params'])){
+            foreach($_REQUEST['back_params'] as
+                    $back_param_key => $back_param_value){
+                $data['BACK_PARAMS']["back_params[$back_param_key]"]
+                    = $back_param_value;
+                $data["OTHER_BACK_URL"] .= "&amp;back_params[$back_param_key]"
+                    ."=" . $back_param_value;
+            }
+            $data['BACK_URL'] = http_build_query($_REQUEST["back_params"]);
+        }
+
+        if (isset($_REQUEST['open_help_page'])) {
+            $data['OPEN_HELP_PAGE'] = $_REQUEST['open_help_page'];
+            if (!isset($data['SCRIPT'])) {
+                $data['SCRIPT'] = "";
+            }
+
+            $data['SCRIPT'] .= "\n" .
+                'var matches = '
+                . 'document.querySelectorAll("[data-pagename='
+                . $data['OPEN_HELP_PAGE']
+                . ']");'
+                . "matches[0].click();"
+                . "\n";
+        }
+        return $data;
+    }
+    /**
      * When an activity involves displaying tabular data (such as rows of
      * users, groups, etc), this method might be called to set up $data
      * fields for next, prev, and page links, it also makes the call to the
diff --git a/css/search.css b/css/search.css
index 696c537..7e89ba2 100755
--- a/css/search.css
+++ b/css/search.css
@@ -2861,3 +2861,7 @@ top: 1in;
 .wiki-resource-image{
     max-width:100%;
 }
+.back-button{
+    margin-top : 5px;
+    margin-bottom : 10px;
+}
\ No newline at end of file
diff --git a/resources/back.png b/resources/back.png
new file mode 100644
index 0000000000000000000000000000000000000000..eee5c8297b17d87b6bdc26e4ba2384b9266b1090
GIT binary patch
diff --git a/scripts/basic.js b/scripts/basic.js
index 6ab029c..279522e 100755
--- a/scripts/basic.js
+++ b/scripts/basic.js
@@ -383,15 +383,15 @@ function getPageWithCallback(url, response_type, success_call_back,
  * @param String api_action api's action name.
  * @param String mode r/w mode , usually read.
  */
-function displayHelpForId( help_point, is_mobile, target_controller,
-    csrf_token_key, csrf_token_value, help_group_id, api_controller,
-    api_action, mode)
-{
+function displayHelpForId(help_point, is_mobile, target_controller,
+                          current_action, csrf_token_key, csrf_token_value,
+                          help_group_id,
+                          api_controller, api_action, mode) {
     if ((elt("help-frame").style.display) === "block") {
         toggleHelp('help-frame', is_mobile, target_controller);
         return;
     }
-    var tl = eval( '(' + help_point.getAttribute("data-tl") + ')' );
+    var tl = eval('(' + help_point.getAttribute("data-tl") + ')');
     getPageWithCallback("?c=" + api_controller + "&group_id=" +
         help_group_id + "&" +
         "arg=" + mode + "&" +
@@ -399,24 +399,25 @@ function displayHelpForId( help_point, is_mobile, target_controller,
         csrf_token_key + '=' + csrf_token_value + "&" +
         "page_name=" + help_point.getAttribute("data-pagename"),
         'json',
-        function(data) {
+        function (data) {
             elt("help-frame-body").innerHTML = parseWikiContent(
                 data.wiki_content,
                 data.group_id,
                 data.page_id
             );
             elt('page_name').innerHTML = data.page_name + ' [<a href="' +
-                getEditLink(
-                    target_controller,
-                    csrf_token_key,
-                    csrf_token_value,
-                    help_group_id,
-                    data.page_name) + '">' +
-                tl["wiki_view_edit"] + '</a>]';
+            getEditLink(
+                target_controller,
+                current_action,
+                csrf_token_key,
+                csrf_token_value,
+                help_group_id,
+                data.page_name) + '">' +
+            tl["wiki_view_edit"] + '</a>]';
 
             toggleHelp('help-frame', is_mobile, target_controller);
         },
-        function(status) {
+        function (status) {
             toggleHelp('help-frame', is_mobile, target_controller);
         });
     event.preventDefault();
@@ -431,13 +432,15 @@ function displayHelpForId( help_point, is_mobile, target_controller,
  * @param String page_name Page name,unique Identifier for wiki edit page.
  * @return String the edit link
  */
-function getEditLink(target_controller, csrf_token_key, csrf_token_value,
-    group_id, page_name)
-{
+function getEditLink(target_controller, current_action, csrf_token_key,
+                     csrf_token_value, group_id, page_name) {
     return '?c=' + target_controller +
-        '&' + csrf_token_key + '=' + csrf_token_value +
-        '&group_id=' + group_id +
-        '&arg=edit' +
-        '&a=wiki' +
-        '&page_name=' + page_name;
+    '&' + csrf_token_key + '=' + csrf_token_value +
+    '&group_id=' + group_id +
+    '&arg=edit' +
+    '&a=wiki' +
+    '&page_name=' + page_name +
+    '&back_params[open_help_page]=' + page_name +
+    '&back_params[c]=' + target_controller +
+    '&back_params[a]=' + current_action;
 }
diff --git a/views/elements/wiki_element.php b/views/elements/wiki_element.php
index a6080db..2c1dc28 100644
--- a/views/elements/wiki_element.php
+++ b/views/elements/wiki_element.php
@@ -69,6 +69,9 @@ class WikiElement extends Element implements CrawlConstants
         $other_base_query = "?c=$other_controller&amp;a=wiki&amp;group_id=".
             $data["GROUP"]["GROUP_ID"]."&amp;arg=".$data['MODE']."&amp;".
             "page_name=".$data['PAGE_NAME'];
+        if(isset($data['OTHER_BACK_URL'])){
+            $other_base_query .= $data['OTHER_BACK_URL'];
+         }
         if($logged_in) {
             $other_base_query .= $csrf_token;
             $csrf_token = "&amp;".CSRF_TOKEN."=".$data[CSRF_TOKEN];
@@ -105,6 +108,14 @@ class WikiElement extends Element implements CrawlConstants
             }
             e('<div class="small-margin-current-activity '.$page_border.'">');
         }
+        if (isset($data['BACK_URL'])) {
+            e("<div class=\"float-opposite back-button\">" .
+                "<a href=\"?" . $data['BACK_URL'] . "&amp;" . CSRF_TOKEN
+                . "=" . $data[CSRF_TOKEN] . "\">" .
+                "<img src=\"resources/back.png\" />" .
+                "</a>" .
+                "</div>");
+        }
         if(isset($data['MEDIA_NAME'])) {
             ?>
             <div class="top-margin"><b><a href="<?php e($base_query .
@@ -148,6 +159,9 @@ class WikiElement extends Element implements CrawlConstants
                     if($name != 'pages') {
                         $append = '&amp;page_name='. $data['PAGE_NAME'];
                     }
+                    if (isset($data['OTHER_BACK_URL'])) {
+                        $append .= $data['OTHER_BACK_URL'];
+                    }
                     e($bar); ?><a href="<?php e($base_query .
                         '&amp;arg='.$name.'&amp;a=wiki'.$append); ?>"><?php
                         e($translation); ?></a><?php
@@ -275,6 +289,19 @@ class WikiElement extends Element implements CrawlConstants
                 e($data[CSRF_TOKEN]); ?>" />
             <input type="hidden" name="a" value="wiki" />
             <input type="hidden" name="arg" value="edit" />
+            <?php
+            if(isset($data['BACK_PARAMS']))
+            {
+                foreach($data["BACK_PARAMS"] as
+                        $back_param_key => $back_param_value){
+                    e('<input type="hidden" '
+                        . 'name="'.$back_param_key.
+                        '" value="'.
+                        $back_param_value
+                        .'" />');
+                }
+            }
+            ?>
             <input type="hidden" name="group_id" value="<?php
                 e($data['GROUP']['GROUP_ID']); ?>" />
             <input type="hidden" name="page_name" value="<?php
diff --git a/views/helpers/helpbutton_helper.php b/views/helpers/helpbutton_helper.php
index ad7154d..26fb1fc 100644
--- a/views/helpers/helpbutton_helper.php
+++ b/views/helpers/helpbutton_helper.php
@@ -65,11 +65,11 @@ class HelpbuttonHelper extends Helper
      *
      * @param  $help_point_id - used to set as help button id
      * @param  $csrf_token_value - csrf token to make api call/open edit link
-     * @param  $target_c - target controller to remember the view.
+     * @param  $target_controller - target controller to remember the view.
      * @return String button html.
      */
     public function render($help_point_id,
-                           $csrf_token_value, $target_c) {
+                           $csrf_token_value, $target_controller) {
         $is_mobile = MOBILE ? "true" : "false";
         $wiki_group_id = "7";
         $api_controller = "api";
@@ -77,10 +77,14 @@ class HelpbuttonHelper extends Helper
         $api_wiki_mode = "read";
 
         return '<button type="button"
-                    data-tl=\''.$this->localizationdata.'\'
-                    onclick="javascript:displayHelpForId(this,'
-        . $is_mobile . ',\'' . $target_c . '\',\''. CSRF_TOKEN .'\',\''
-        . $csrf_token_value ."','$wiki_group_id','$api_controller',"
+                    data-tl=\'' . $this->localizationdata . '\'
+                    onclick="javascript:displayHelpForId(
+                    this,'
+        . $is_mobile . ',\''
+        . $target_controller . '\',\''
+        . $_REQUEST['a'] . '\',\''
+        . CSRF_TOKEN . '\',\''
+        . $csrf_token_value . "','$wiki_group_id','$api_controller',"
         . "'$api_wiki_action','$api_wiki_mode" . '\')" '
         . 'data-pagename="' . $help_point_id . '">?</button>';
     }
diff --git a/views/wiki_view.php b/views/wiki_view.php
index 32df361..1e0b15c 100644
--- a/views/wiki_view.php
+++ b/views/wiki_view.php
@@ -108,6 +108,9 @@ class WikiView extends View
                     if($name != 'pages') {
                         $append = '&amp;page_name='. $data['PAGE_NAME'];
                     }
+                    if (isset($data['OTHER_BACK_URL'])) {
+                        $append .= $data['OTHER_BACK_URL'];
+                    }
                     ?>
                     <li class="outer"><a href="<?php e($base_query .
                         '&amp;arg='.$name.'&amp;a=wiki'.$append); ?>"><?php
-- 
1.9.3 (Apple Git-50)

