var App = window.App || {};

App.Create = (function ($, w) {

    'use strict';

    function Create ($el, options) {

        if (typeof $el.midgardCreate !== 'function') {
            return;
        }

        this.options = $.extend({}, Create.defaults, options);

        $el.midgardCreate();

        w.Backbone.sync = this.sync.bind(this);
    }

    // Override Backbone.sync
    Create.prototype.sync = function(method, model, options) {

        // only update implemented
        if (method !== 'update') {
            return options.error(model);
        }

        this.id = Create.extractId(model.id);

        $.ajax({
            url: '/pages/' + this.id,
            type: 'put',
            data: model.toJSON(),
            dataType: 'json',
            success: function () {
                options.success(model);
            },
            error: function () {
                options.error(model);
            }
        });

    };

    Create.extractId = function(id) {
        return parseInt(id.replace(/<\/pages\/(\d+)>/, '$1'), 10);
    };

    Create.defauts = {

    };

    return Create;

}(jQuery, window));

@@ -269,16 +269,27 @@
 %0A       
+ this.$el =
  $el.mid
@@ -299,16 +299,824 @@
 dCreate(
+%7B%0A            url: function () %7B%0A                if (this.isNew() && this.collection) %7B%0A                    return this.collection.url;%0A                %7D%0A%0A                return this.getSubjectUri();%0A            %7D,%0A            editorOptions: %7B%0A                hallo: %7B%0A                    widget: 'halloWidget',%0A                    options: %7B%0A                        plugins: %7B%0A                            halloformat: %7B%0A                                formattings: %7B%7D%0A                            %7D,%0A                            halloblock: %7B%0A                                elements: %5B'p', 'h2', 'h3'%5D%0A                            %7D,%0A                            hallolink: %7B%7D,%0A                            hallolists: %7B%7D%0A                        %7D%0A                    %7D%0A                %7D%0A            %7D%0A        %7D
 );%0A%0A    
@@ -1158,16 +1158,42 @@
 d(this);
+%0A%0A        return this.$el;
 %0A    %7D%0A%0A
@@ -1298,88 +1298,350 @@
     
-// only update implemented%0A        if (method !== 'update') %7B%0A            return
+if (method === 'update') %7B%0A%0A            $.ajax(%7B%0A                url: model.url(),%0A                type: 'put',%0A                data: model.toJSON(),%0A            %C2%A0%C2%A0%C2%A0%C2%A0dataType: 'json',%0A                success: function () %7B%0A                    options.success(model);%0A                %7D,%0A                error: function () %7B%0A                   
  opt
@@ -1671,58 +1671,82 @@
     
+   
-%7D%0A%0A        this.id = Create.extractId(model.id);%0A%0A
+     %7D%0A            %7D);%0A%0A        %7D else if (method === 'create') %7B%0A%0A    
     
@@ -1774,34 +1774,34 @@
     
+    
 url: 
-'/pages/' + this.id,%0A
+model.url(),%0A    
     
@@ -1808,37 +1808,42 @@
         type: 'p
-u
+os
 t',%0A
+    
             data
@@ -1860,32 +1860,36 @@
 JSON(),%0A        
+  
+  
 %C2%A0%C2%A0%C2%A0%C2%A0dataType: 'j
@@ -1886,32 +1886,36 @@
 taType: 'json',%0A
+    
             succ
@@ -1941,32 +1941,36 @@
                 
+   
+ 
 options.success(
@@ -1981,35 +1981,42 @@
 l);%0A            
-%7D,%0A
+    %7D,%0A   
             erro
@@ -2003,32 +2003,33 @@
 %0A               
+ 
 error: function 
@@ -2025,32 +2025,36 @@
 : function () %7B%0A
+    
                 
@@ -2079,34 +2079,42 @@
 l);%0A            
+   
+ 
 %7D%0A
+    
         %7D);%0A%0A   
@@ -2106,24 +2106,92 @@
        %7D);%0A%0A
+        %7D else %7B%0A            return options.error(model);%0A        %7D%0A
     %7D;%0A%0A    

Support for creating records.