Merge branch 'master' of stigma.nowoczesnapolska.org.pl:platforma into view-refactor
authorzuber <marek@stepniowski.com>
Mon, 28 Sep 2009 14:44:53 +0000 (16:44 +0200)
committerzuber <marek@stepniowski.com>
Mon, 28 Sep 2009 14:44:53 +0000 (16:44 +0200)
apps/api/handlers/library_handlers.py
apps/api/tests/__init__.py
project/static/js/views/button_toolbar.js
project/templates/toolbar_api/scriptlets.js

index 64b95c2..5696cc9 100644 (file)
@@ -276,19 +276,21 @@ class DocumentTextHandler(BaseHandler):
 
                 # now that the parts are ok, write xml
                 f = lib._fileopen(resolve('xml'), 'w+')
-                f.write(data)
+                f.write(data.encode('utf-8'))
                 f.close()
-                
+
+            ndoc = None
             ndoc = current.invoke_and_commit(\
                 xml_update_action, lambda d: (msg, current.owner) )
 
             try:
                 # return the new revision number
-                return response.SuccessAllOk.django_response({
+                return response.SuccessAllOk().django_response({
                     "document": ndoc.id,
                     "subview": "xml",
                     "previous_revision": current.revision,
-                    "updated_revision": ndoc.revision
+                    "updated_revision": ndoc.revision,
+                    "url": reverse("doctext_view", args=[ndoc.id, ndoc.revision])
                 })
             except Exception, e:
                 if ndoc: lib._rollback()
index f28b3b2..751a085 100644 (file)
@@ -32,10 +32,11 @@ def temprepo(name):
             finally:
                 if not clean and self.response:
                     print "RESULT", func.__name__, ">>>"
-                    print self.response
+                    print self.response.content
                     print "<<<"
-
-                # shutil.rmtree(temp, True)
+                else:
+                    shutil.rmtree(temp, True)
+                
                 settings.REPOSITORY_PATH = ''
            
         return decorated
@@ -141,24 +142,26 @@ class SimpleTest(TestCase):
         self.response = self.client.get(resp['text_url'])
         self.assertEqual(self.response.status_code, 200)
         self.assertEqual(self.response.content, "Ala ma kota\n")
-#
-#
-#    @temprepo('simple')
-#    def test_document_text_update(self):
-#        self.assertTrue(self.client.login(username='admin', password='admin'))
-#        TEXT = u"Ala ma kota i psa"
-#
-#        self.response = self.client.put( \
-#            reverse("doctext_view", args=['testfile']), {'contents': TEXT })
-#        self.assertEqual(self.response.status_code, 200)
-#
-#        self.response = self.client.get( \
-#            reverse("doctext_view", args=['testfile']) )
-#        self.assertEqual(self.response.status_code, 200)
-#        self.assertEqual(self.response.content, TEXT)
+
+
+    @temprepo('simple')
+    def test_document_text_update(self):
+        self.assertTrue(self.client.login(username='admin', password='admin'))
+        TEXT = u"Ala ma kota i psa"
+
+        self.response = self.client.get(
+            reverse("document_view", args=['sample']) )
+            
+        resp = self.assert_json_response()
+
+        self.response = self.client.put(resp['text_url'], {'contents': TEXT })
+        result = self.assert_json_response(must_have={u'document': u'sample'} )
+        
+        #self.response = self.client.get(result['url'])
+        #self.assertEqual(self.response.content, TEXT)
 
     def assert_json_response(self, must_have={}, exclude=[], code=200):
-        self.assertEqual(self.response.status_code, code)
+        self.assertEqual(self.response.status_code, code)        
         result = json.loads(self.response.content)
 
         for (k,v) in must_have.items():
index 11cc148..3e0a148 100644 (file)
@@ -39,14 +39,14 @@ var ButtonToolbarView = View.extend({
       $(self.element).trigger('resize');
     });
     
-    $('.buttontoolbarview-button', this.element).bind('click.buttontoolbarview', function() {
+    $('.buttontoolbarview-button', this.element).bind('click.buttontoolbarview', function(event) {
       var groupIndex = parseInt($(this).attr('ui:groupindex'), 10);
       var buttonIndex = parseInt($(this).attr('ui:buttonindex'), 10);
       var button = self.get('buttons')[groupIndex].buttons[buttonIndex];
       var scriptletId = button.scriptlet_id;
       var params = eval('(' + button.params + ')'); // To nie powinno być potrzebne
       console.log('Executing', scriptletId, 'with params', params);
-      scriptletCenter[scriptletId](self.parent, params);
+      scriptletCenter.scriptlets[scriptletId](self.parent, params);
     });
     
     $(this.element).trigger('resize');
index 801e5d3..6f5258c 100644 (file)
@@ -8,8 +8,23 @@ function ScriptletCenter() {
         {% endfor %}
 
         _none: null
-    };
+    };   
             
 }
 
+ScriptletCenter.prototype.XMLEditorSelectedText = function(panel) {
+    return panel.contentView.editor.selection();
+}
+
+ScriptletCenter.prototype.XMLEditorReplaceSelectedText = function(panel, replacement)
+{
+    panel.contentView.editor.replaceSelection(replacement);
+    /* TODO: fire the change event */
+}
+
+ScriptletCenter.prototype.XMLEditorMoveCursorForward = function(panel, n) {
+    var pos = panel.contentView.editor.cursorPosition();
+    panel.contentView.editor.selectLines(pos.line, pos.character + n);
+}
+
 scriptletCenter = new ScriptletCenter();
\ No newline at end of file