]> git.openstreetmap.org Git - osqa.git/blobdiff - forum/skins/default/templates/question_edit.html
should now be working for chrome/safari/firefox. still need to fix markdown display...
[osqa.git] / forum / skins / default / templates / question_edit.html
index fe711849006390ba64b0f5bd52685a8a5cd505d1..402a0eb56b27a8e48214ad35c0053b8fe07564e4 100644 (file)
@@ -4,9 +4,6 @@
 {% load extra_tags %}
 {% block title %}{% spaceless %}{% trans "Edit question" %}{% endspaceless %}{% endblock %}
 {% block forejs %}
-        <script type='text/javascript' src='{% media  "/media/js/com.cnprog.editor.js" %}'></script>
-        <script type='text/javascript' src='{% media  "/media/js/com.cnprog.post.js" %}'></script>
-        <script type='text/javascript' src='{% media  "/media/js/jquery.validate.pack.js" %}'></script>
         <script type='text/javascript' src='{% media  "/media/js/wmd/showdown.js" %}'></script>
         <script type='text/javascript' src='{% media  "/media/js/wmd/wmd.js" %}'></script>
         <link rel="stylesheet" type="text/css" href="{% media  "/media/js/wmd/wmd.css" %}" />
             $("#nav_questions").attr('className',"on");
             $('#editor').TextAreaResizer();
             
-            //highlight code synctax when editor has new text
-            $("#editor").typeWatch({highlight: false, wait: 3000,
-                             captureLength: 5, callback: lanai.highlightSyntax});
-                             
+
             //toggle preview of editor
             var display = true;
             var txt = "[{% trans "hide preview" %}]";
@@ -32,8 +26,7 @@
             });
             
             //Tags autocomplete action
-            var tags = {{ tags|safe }};
-               $("#id_tags").autocomplete(tags, {
+               $("#id_tags").autocomplete("/matching_tags/", {
                        matchContains: true,
                 max: 20,
                 multiple: true,
                 highlightItem: true,
                 scroll: true,
                 scrollHeight: 300,
-                       formatItem: function(row, i, max) {
+                       /*formatItem: function(row, i, max) {
                                return row.n + " ("+ row.c +")";
                        },
                 formatResult: function(row, i, max){
                     return row.n;
+                }*/
+                formatItem: function(row, i, max, value) {
+                    return row[1].split(".")[0] + " (" + row[1].split(".")[1] + ")";
+                },
+
+                formatResult: function(row, i, max, value){
+                    return row[0];
                 }
                 
-            });
-            
-            setupFormValidation("#fmedit", CPValidator.getQuestionFormRules(), CPValidator.getQuestionFormMessages());
-            
+            });         
+
             $('#id_revision').unbind().change(function(){
                 $("#select_revision").click();
             });
-            lanai.highlightSyntax();
-            
+
+            init = $("textarea#editor")[0].value;
+
+            title = $("input#id_title")[0].value;
+            body = $("textarea#editor")[0].value;
+            tag = $("input#id_tags")[0].value;
         });
+
+        function submitClicked(e) {
+            if(!(browserTester('chrome') || browserTester('safari'))) {
+                $("input.submit")[0].disabled=true;
+                $("input.submit")[1].disabled=true;
+            }
+            window.removeEventListener('beforeunload', beforeUnload, true);
+        }
+
+        function beforeUnload(e) {
+            if($("input#id_title")[0].value != title || $("textarea#editor")[0].value != body || $("input#id_tags")[0].value != tag) {
+                 return yourWorkWillBeLost(e);
+            }
+        }
+        window.addEventListener('beforeunload', beforeUnload, true);
+
+        var init = "";
+        var title = "";
+        var body = "";
+        var tag = "";
         </script>
 {% endblock %}
         
                 {{ form.summary.help_text }}
             </div>
             <div class="error" ></div>
-            <input type="submit" value="{% trans "Save edit" %}" class="submit" />
-            <input type="button" value="{% trans "Cancel" %}" class="submit" onclick="history.back(-1);" />
+            <input type="submit" value="{% trans "Save edit" %}" class="submit" onclick="submitClicked(event)" />
+            <input type="button" value="{% trans "Cancel" %}" class="submit" onclick="history.back(-1);submitClicked(event)" />
         </form>
     </div>
 </div>