proper type dropdown for files now
authorChristian Weiske <cweiske@cweiske.de>
Tue, 3 Apr 2012 06:29:37 +0000 (08:29 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Tue, 3 Apr 2012 06:29:37 +0000 (08:29 +0200)
data/templates/edit-add.htm
data/templates/edit-file.htm
src/Phorkie/HtmlHelper.php [new file with mode: 0644]
www/edit.php
www/index.php

index 8435852d8ebea2f8336ce54413394e40f6a36c1a..19f10cf4697ddaa6601ae1fc07db87e27269af3a 100644 (file)
@@ -5,7 +5,7 @@
     </a>
  </div>
 
- {% include 'edit-file.htm' with {'file': '', 'fileid': 'new'} %}
+ {% include 'edit-file.htm' with {'file': null, 'fileid': 'new'} %}
 
 <script type="application/javascript">
 $(document).ready(function() {
@@ -13,7 +13,7 @@ $(document).ready(function() {
     $('#filegroupnew').hide();
     $('#add-button a').bind('click', function() {
         $('#add-button').before("{% filter escape('js') %}
-            {% include 'edit-file.htm' with {'file': '', 'fileid': '###'} %}
+            {% include 'edit-file.htm' with {'file': null, 'fileid': '###'} %}
             {% endfilter %}"
             .replace(/###/g, $('.filegroup').length)
         );
index ef900eacfe209d68023adc9147696ac3dc8bca6e..37f92538486aa853925965460573a7ef86cd40c6 100644 (file)
@@ -9,9 +9,7 @@
     <label for="type_{{fileid}}">Type</label>
     <!-- fixme: preselect -->
     <select name="files[{{fileid}}][type]" id="type_{{fileid}}">
-     <option value="css">CSS</option>
-     <option value="php">PHP</option>
-     <option value="xml">XML</option>
+     {{htmlhelper.getLanguageOptions(file)|raw}}
     </select>
    </div>
   </div>
diff --git a/src/Phorkie/HtmlHelper.php b/src/Phorkie/HtmlHelper.php
new file mode 100644 (file)
index 0000000..f20add3
--- /dev/null
@@ -0,0 +1,28 @@
+<?php
+namespace Phorkie;
+
+class HtmlHelper
+{
+    public function getLanguageOptions(File $file = null)
+    {
+        $html = '';
+        $fileExt = null;
+        if ($file !== null) {
+            $fileExt = $file->getExt();
+        }
+        foreach ($GLOBALS['phorkie']['languages'] as $ext => $arLang) {
+            if (isset($arLang['show']) && !$arLang['show']) {
+                continue;
+            }
+            $html .= sprintf(
+                '<option value="%s"%s>%s</option>',
+                $ext,
+                $fileExt == $ext ? ' selected="selected"' : '',
+                $arLang['title']
+            ) . "\n";
+        }
+        return $html;
+    }
+}
+
+?>
\ No newline at end of file
index 9acc1d69fe12d992927136e0ef63df18b2567fb3..e59bcd1f55518e4ece3b5b0012fb345c557e40d5 100644 (file)
@@ -17,6 +17,7 @@ render(
     'edit',
     array(
         'repo' => $repo,
+        'htmlhelper' => new HtmlHelper(),
     )
 );
 ?>
index 9a03b77c91e0ad223309d43857bbae9828d9a3a2..898c443a72309ce53097286fc1a74f845855e280 100644 (file)
@@ -20,5 +20,12 @@ if ($repopo->process($_POST)) {
 $phork = array(
     '1' => new File(null, null)
 );
-render('index', array('files' => $phork, 'description' => ''));
+render(
+    'index',
+    array(
+        'files' => $phork,
+        'description' => '',
+        'htmlhelper' => new HtmlHelper(),
+    )
+);
 ?>