Commits

Dimitris Glezos  committed 03fd447

Make expr editing work with highlighting and escaping.

  • Participants
  • Parent commits 76527d4

Comments (0)

Files changed (2)

File txclib/commands.py

             r_url = '%s/resource/%s' % (p_url, r)
             sfile = prj.get_resource_option(res, 'source_file') or "N/A"
             expr = prj.config.get(res, "file_filter")
-            # Remove until we figure out a way to edit in a sane way
-            # expr_highlight = expr.replace('<lang>', '<span class="lang">&lt;lang&gt;</span>')
-            expr_highlight = expr.replace('<lang>', '$lang')
+            expr_highlight = expr.replace('<lang>', '<span class="lang">&lt;lang&gt;</span>')
             res_list.append({'id': res,
                              'p_name': p,
                              'p_url': p_url,
         prj = project.Project(path_to_tx)
         res_id = request.form['res_id']
         expr = request.form['value']
-        new_expr = expr.replace('$lang', '<lang>')
-        logger.info("Changing expression of %s to %s" % (res_id, new_expr))
-        prj.config.set("%s" % res_id, "file_filter", new_expr)
+        logger.info("Changing expression of %s to %s" % (res_id, expr))
+        prj.config.set("%s" % res_id, "file_filter", expr)
         prj.save()
         return expr
 

File txclib/templates/home.html

   }, {  });
 
   /* Modify resource expr */
-  $('.resexpr.edit').editable(ACTIONS["modify_expr"].url, {
-    id: 'elementid',
-    style: 'display: inline',
-    tooltip: 'Click to edit...',
-    submitdata: {res_id: $('.resexpr.edit').attr('data-id')}
-  }, {  });
+  $('.resexpr.edit').editable(function(value, settings) {
+  
+    $.ajax({
+      type : "POST",
+      cache : false,
+      url  : ACTIONS["modify_expr"].url,
+      dataType: 'json',
+      data : { 'res_id': $('.resexpr.edit').attr('data-id'),
+               'value': value },
+      success : function(data) {
+       if (data.status == 'ok') {
+        alert('ok');
+        return data.title;
+       } else {
+        alert('n/ok');
+        return this.revert;   
+       }
+
+    }});
+
+      return value.replace('<lang>', '<span class="lang">&lt;lang&gt;</span>');
+
+    }, {
+      style: 'display: inline',
+      tooltip: 'Click to edit...',
+      data: function(value, settings) {
+        /* Convert $lang to aaa. */
+        return value.replace('<span class="lang">&lt;lang&gt;</span>', '<lang>');
+      },
+    });
 
 });
 
     </td>
     <td>
       <dl>
-        <dd><span class="edit resexpr" data-id="{{ res.id }}">{{ res.expr_highlight }}</span></dd>
+        <dd><span class="edit resexpr" data-id="{{ res.id }}">{{ res.expr_highlight|safe }}</span></dd>
       </dl>
     </td>
     <td class="actions">