Make add to page work with subfolders, a=chris

Chris Pollett [2016-03-07 18:Mar:th]
Make add to page work with subfolders, a=chris
Filename
src/css/search.css
src/scripts/wiki.js
src/views/elements/WikiElement.php
diff --git a/src/css/search.css b/src/css/search.css
index 4400ad323..008a21a34 100755
--- a/src/css/search.css
+++ b/src/css/search.css
@@ -2621,6 +2621,14 @@ table.wikitable > caption
 {
     font-weight:bold;
 }
+.resource-actions
+{
+    min-width:2in;
+}
+.mobile .resource-actions
+{
+    min-width:100px;
+}
 .resource-list td
 {
     padding:3px;
@@ -2645,9 +2653,9 @@ table.wikitable > caption
 #label-docs-form th,
 #label-docs-queue .actions
 {
-    font-weight: normal;
-    padding: 0.1in 0.2in 0.1in 0in;
-    width: 1.0in;
+    font-weight:normal;
+    padding:0.1in 0.2in 0.1in 0in;
+    width:1.0in;
 }
 #label-docs-queue .actions
 {
diff --git a/src/scripts/wiki.js b/src/scripts/wiki.js
index f2c43f36b..f23661d27 100755
--- a/src/scripts/wiki.js
+++ b/src/scripts/wiki.js
@@ -787,11 +787,20 @@ function enableKBShortcuts(id)
 }
 /*
  * Used to add the wiki text for including a resource into a wiki page
+ * @param String resource_name string name of resource to be added
  * @param String id identifier of the textarea used to insert wiki text
+ * @param String sub_path path in resource folder to reasource
  */
-function addToPage(resource_name, textarea_id)
+function addToPage(resource_name, textarea_id, sub_path)
 {
-    wikify("((resource:", "|" + tl['wiki_js_resource_description'] +
-        resource_name.replace('"', '"') + "))",
-        resource_name.replace('"', '"'), textarea_id);
+    if (typeof sub_path === 'undefined' || sub_path == '') {
+        wikify("((resource:", "|" + tl['wiki_js_resource_description'] +
+            resource_name.replace('"', '"') + "))",
+            resource_name.replace('"', '"'), textarea_id);
+    } else {
+        wikify("((resource:", "|" +sub_path +
+            "|" + tl['wiki_js_resource_description'] +
+            resource_name.replace('"', '"') + "))",
+            resource_name.replace('"', '"'), textarea_id);
+    }
 }
diff --git a/src/views/elements/WikiElement.php b/src/views/elements/WikiElement.php
index 1d92ec9a6..141a9c65e 100644
--- a/src/views/elements/WikiElement.php
+++ b/src/views/elements/WikiElement.php
@@ -657,7 +657,7 @@ class WikiElement extends Element implements CrawlConstants
                     ?><tr><th></th><th><a href='<?=
                         $folder_prefix?>&amp;sort=name'><?=
                         tl('wiki_element_name')
-                    ?></a></th><th colspan="2"><form>
+                    ?></a></th><th colspan="2" class="resource-actions"><form>
                     <input type="hidden" name='<?=C\CSRF_TOKEN?>'
                         value='<?=$data[C\CSRF_TOKEN]?>' />
                     <input type="hidden" name='arg' value='edit' />
@@ -768,11 +768,14 @@ class WikiElement extends Element implements CrawlConstants
                             <?= $i ?>)' ><?=
                             tl('wiki_element_rename') ?></button><?php
                         }
-                        if (!$disabled && (!isset($data['page_type']) ||
+                        if (!$disabled && empty($resource['is_dir'])
+                            && (!isset($data['page_type']) ||
                             $data['page_type'] != 'media_list')) { ?>
                             <button onclick='javascript:addToPage("<?=
                             str_replace("&quot;", "&amp;quot;", $name);
-                            ?>", "wiki-page")'><?=tl('wiki_element_add_to_page')
+                            ?>", "wiki-page"<?= (empty($data['SUB_PATH'])) ?
+                            "" : ", \"{$data['SUB_PATH']}\""
+                            ?>)'><?=tl('wiki_element_add_to_page')
                             ?></button> <?php
                         }
                         e("</td>");
ViewGit