Commits

Anonymous committed 8705773

Fix query.edit delete button.

As part of this, remove the section that shows retired queries.
If we delete a query, it is because we don't want to see it
any more.

Comments (0)

Files changed (1)

html/query.edit.html

  i18n:translate="">You are not allowed to edit queries.</span>
 
 <script language="javascript">
-// This exists solely because I can't figure how to get the & into an
-// attributes TALES expression, and so it keeps getting quoted.
+// This allows us to make the delete button is an immediate action.
+// The post_to_url function comes from:
+//    http://stackoverflow.com/questions/133925/javascript-post-request-like-a-form-submit
 function retire(qid) {
-    window.location = 'query'+qid+'?@action=retire&@template=edit';
+    post_to_url('query'+qid, {'@action': 'retire', '@template': 'edit'});
+}
+function post_to_url(path, params, method) {
+    method = method || "post"; // Set method to post by default if not specified.
+
+    var form = document.createElement("form");
+    form.setAttribute("method", method);
+    form.setAttribute("action", path);
+
+    for(var key in params) {
+        if(params.hasOwnProperty(key)) {
+            var hiddenField = document.createElement("input");
+            hiddenField.setAttribute("type", "hidden");
+            hiddenField.setAttribute("name", key);
+            hiddenField.setAttribute("value", params[key]);
+
+            form.appendChild(hiddenField);
+         }
+    }
+
+    document.body.appendChild(form);
+    form.submit();
 }
 </script>
 
     <th>&nbsp;</th>
 </tr>
 
-<tr tal:repeat="query mine">
- <tal:block condition="query/is_retired">
-
+<!-- RDM20140305: We ought to be able to use a filterspec here and below
+     instead of a condition, but I couldn't get it to work. -->
+<tr tal:define="queries python:db.query.filter()"
+     tal:repeat="query queries">
+ <tal:block tal:condition="python:query.creator == uid and not path('query/is_retired')">
  <td><a tal:attributes="href string:${query/klass}?${query/url}"
         tal:content="query/name">query</a></td>
 
   </select>
  </td>
 
- <td colspan="3" i18n:translate="">[query is retired]</td>
-
- <!-- <td> maybe offer "restore" some day </td> -->
- </tal:block>
-</tr>
-
-<!-- RDM20140305: We ought to be able to use a filterspec here and below
-     instead of a condition, but I couldn't get it to work. -->
-<tr tal:define="queries python:db.query.filter()"
-     tal:repeat="query queries">
- <tal:block tal:condition="python:query.creator == uid and not path('query/is_retired')">
- <td><a tal:attributes="href string:${query/klass}?${query/url}"
-        tal:content="query/name">query</a></td>
-
- <td metal:use-macro="template/macros/include" />
-
  <td><a tal:attributes="href string:query${query/id}" i18n:translate="">edit</a></td>
 
  <td>