define([
    'jquery',
    'underscore',
    'backbone',
    'app',
    'simplemde',
    'models/testcase/TestCaseModel',
    'text!templates/testcases/testCaseTemplate.html'
], function($, _, Backbone, app, SimpleMDE, TestCaseModel, testCaseTemplate) {

    var TestCaseView = Backbone.View.extend({

        events: {
            'submit form': 'save'
        },

        initialize: function() {
            _.bindAll(this, 'render', 'save');
        },

        render: function(options) {
            this.model = options.model;
            var data = {
                testcase: this.model,
                projectId: options.project_id,
                testSuiteId: options.test_suite_id,
                _: _
            }
            var compiledTemplate = _.template(testCaseTemplate, data);
            this.$el.html(compiledTemplate);
            this.description_simplemde = new SimpleMDE({
                autoDownloadFontAwesome: true, 
                autofocus: false,
                autosave: {
                    enabled: false
                },
                element: this.$('#testcase-description-input')[0],
                indentWithTabs: false,
                spellChecker: false,
                tabSize: 4
            });
            this.description_simplemde.value(this.model.get('version')['description']);
            this.prerequisite_simplemde = new SimpleMDE({
                autoDownloadFontAwesome: true, 
                autofocus: false,
                autosave: {
                    enabled: false
                },
                element: this.$('#testcase-prerequisite-input')[0],
                indentWithTabs: false,
                spellChecker: false,
                tabSize: 4
            });
            this.prerequisite_simplemde.value(this.model.get('version')['prerequisite']);
        },

        save: function(event) {
            event.preventDefault();
            event.stopPropagation();

            if (this.$("#testsuite-form").parsley().validate()) {
                var self = this;
                this.model.save({
                    name: this.$("#testsuite-name-input").val(),
                    description: this.$("#testsuite-description-input").val(),
                }, {
                    wait: true,
                    success: function(mod, res) {
                        app.showAlert('Success!', 'Test Suite ' + this.$("#testsuite-name-input").val() + ' updated!', 'success')
                        Backbone.trigger('nestor:navigationtree_changed');
                        Backbone.history.history.back();
                    },
                    error: function(model, response, options) {
                        var message = _.has(response, 'statusText') ? response.statusText : 'Unknown error!';
                        if (
                            _.has(response, 'responseJSON') &&
                            _.has(response.responseJSON, 'name') &&
                            _.has(response.responseJSON.name, 'length') &&
                            response.responseJSON.name.length > 0
                        ) {
                            message = response.responseJSON.name[0];
                        }
                        app.showAlert('Failed to update Test Suite', message, 'error');
                    }
                });
            } else {
                if (typeof DEBUG != 'undefined' && DEBUG) console.log("Did not pass clientside validation");
            }
        }

    });

    return TestCaseView;

});
@@ -1981,20 +1981,19 @@
 $(%22#test
-suit
+cas
 e-form%22)
@@ -2037,108 +2037,310 @@
     
-var self = this;%0A                this.model.save(%7B%0A                    name: this.$(%22#testsuite-name
+this.collection.create(%7B%0A                    name: this.$(%22#testcase-name-input%22).val(),%0A                    description: this.description_simplemde.value(),%0A                    prerequisite: this.prerequisite_simplemde.value(),%0A                    execution_type_id: this.$(%22#testcase-executiontype_id
 -inp
@@ -2375,30 +2375,28 @@
     
-description
+test_suite_id
 : this.
-$(%22#
 test
@@ -2404,35 +2404,112 @@
 uite
--description-input%22).val(),
+_id,%0A                    project_id: this.projectId,%0A                    created_by: app.session.user_id
 %0A   
@@ -2664,20 +2664,19 @@
 , 'Test 
-Suit
+cas
 e ' + th
@@ -2686,20 +2686,19 @@
 $(%22#test
-suit
+cas
 e-name-i
@@ -3542,24 +3542,24 @@
  to 
-update
+add new
  Test 
-Suit
+Cas
 e', 
@@ -3754,32 +3754,59 @@
 );%0A            %7D
+%0A%0A            return false;
 %0A        %7D%0A%0A    

Update test case function