hide type dropdown when a filename with a dot is given
authorChristian Weiske <cweiske@cweiske.de>
Thu, 5 Apr 2012 05:42:46 +0000 (07:42 +0200)
committerChristian Weiske <cweiske@cweiske.de>
Thu, 5 Apr 2012 05:42:46 +0000 (07:42 +0200)
data/templates/base.htm
data/templates/edit-file.htm
data/templates/edit.htm
data/templates/index.htm
www/phorkie.js [new file with mode: 0644]

index 68c1dab..190a3ea 100644 (file)
@@ -6,6 +6,7 @@
   <link rel="stylesheet" href="/phorkie.css" />
   <title>{% block title %}{% endblock %} - phorkie</title>
   <script src="/jquery-1.7.2.min.js"></script>
+  <script src="/phorkie.js"></script>
  </head>
  <body>
   <div class="navbar">
index fdba0b8..40356ec 100644 (file)
@@ -2,7 +2,7 @@
   <div class="row-fluid">
    <div class="span6">
     <input type="hidden" name="files[{{fileid}}][original_name]" value="{{file.getFilename}}"/>
-    <input type="text" name="files[{{fileid}}][name]" id="filename_{{fileid}}" value="{{file.getFilename}}" placeholder="Filename (optional)"/>
+    <input type="text" name="files[{{fileid}}][name]" id="filename_{{fileid}}" value="{{file.getFilename}}" placeholder="Filename (optional)" class="filename" onchange="filenameChange(this, {{fileid}})" onkeyup="filenameChange(this, {{fileid}})"/>
    </div>
    <div class="span6 typeselect" style="text-align: right" id="typeselect_{{fileid}}">
     <label for="type_{{fileid}}" class="inline">Type</label>
@@ -10,6 +10,9 @@
      {{htmlhelper.getLanguageOptions(file)|raw}}
     </select>
    </div>
+   <div class="span6" style="display:none; text-align: right" id="typetext_{{fileid}}">
+    <p>Type determined from filename</p>
+   </div>
   </div>
   <textarea name="files[{{fileid}}][content]" id="content_{{fileid}}" cols="80" rows="15" class="content">{{file.getContent}}</textarea>
   <div class="row-fluid">
index 6f59309..19494b6 100644 (file)
@@ -29,4 +29,9 @@
  </div>
 
 </form>
+<script type="application/javascript">
+$(document).ready(function() {
+    initFilenames();
+});
+</script>
 {% endblock %}
index d6bd5e1..31913bc 100644 (file)
@@ -20,4 +20,9 @@
  </div>
 
 </form>
+<script type="application/javascript">
+$(document).ready(function() {
+    initFilenames();
+});
+</script>
 {% endblock %}
diff --git a/www/phorkie.js b/www/phorkie.js
new file mode 100644 (file)
index 0000000..20066c4
--- /dev/null
@@ -0,0 +1,26 @@
+function filenameChange(elem, id) {
+    var filename = elem.value;
+    var hasExt = filename.indexOf(".") != -1;
+    if (hasExt) {
+        $('#typeselect_' + id).hide();
+        $('#typetext_' + id).show();
+    } else {
+        $('#typeselect_' + id).show();
+        $('#typetext_' + id).hide();
+    }
+}
+function initFilenames()
+{
+    $('input.filename').each(
+        function(num, elem) {
+            var id = elem.id;
+            var pos = id.indexOf('_');
+            if (pos != -1) {
+                var elemNum = id.substr(pos + 1);
+                if (elemNum != 'new') {
+                    filenameChange(elem, elemNum);
+                }
+            }
+        }
+    );
+}