import getItemModelName from 'appkit/utils/model';

export default Ember.ArrayController.extend({

  sortProperties: ['name'],

  actions: {
    deleteType: function (contentType) {
      if (window.confirm('Are you sure? Confirm to delete this type and all associated data.')) {
        // remove all associated data from Firebase
        window.ENV.firebase.child('data').child(contentType.get('id')).remove();

        // Remove search index info for type
        window.ENV.deleteTypeIndex(contentType.get('id'));

        // remove content type
        contentType.destroyRecord();
      }

    },
    gotoEdit: function (name) {
      this.transitionToRoute('form', name);
    },
    toggleSort: function (property) {
      if (this.get('sortProperties.firstObject') === property) {
        this.toggleProperty('sortAscending');
      } else {
        this.set('sortProperties', [property]);
        this.set('sortAscending', true);
      }
    }
  }
});

@@ -185,16 +185,17 @@
     if (
+!
 window.c
@@ -286,239 +286,2106 @@
     
-// remove all associated data from Firebase%0A        window.ENV.firebase.child('data').child(contentType.get('id')).remove();%0A%0A        // Remove search index info for type%0A        window.ENV.deleteTypeIndex(contentType.get('id'));%0A%0A
+return;%0A      %7D%0A%0A      var allTypesController = this;%0A%0A      var relationPromises = Ember.A(%5B%5D);%0A%0A      var contentTypeName = contentType.get('name');%0A%0A      Ember.Logger.info('Preparing to destroy %60' + contentTypeName + '%60');%0A%0A      // remove relationships from related content types.%0A      // Note: I do not think we need to update the search index of related items as the data that's indexed is just IDs.%0A      Ember.Logger.info('Look for reverse relationships to remove.');%0A      contentType.get('controls').filterBy('controlType.widget', 'relation').forEach(function (control) %7B%0A%0A        var relatedContentTypeId = control.get('meta.data.contentTypeId');%0A        var relatedControlName = control.get('meta.data.reverseName');%0A%0A        Ember.Logger.info('Removing', relatedContentTypeId, ':', relatedControlName);%0A%0A        var relationPromise = new Ember.RSVP.Promise(function (resolve, reject) %7B%0A          allTypesController.store.find('content-type', relatedContentTypeId).then(function (relatedContentType) %7B%0A            relatedContentType.get('controls').filterBy('name', relatedControlName).forEach(function (reverseControl) %7B%0A              relatedContentType.get('controls').removeObject(reverseControl);%0A              relatedContentType.save().then(function () %7B%0A                Ember.Logger.info('Removed', relatedContentTypeId, ':', relatedControlName);%0A                Ember.run(null, resolve);%0A              %7D);%0A            %7D);%0A          %7D);%0A        %7D);%0A%0A        relationPromises.pushObject(relationPromise);%0A%0A      %7D);%0A%0A      // When relations are done...%0A      Ember.RSVP.Promise.all(relationPromises).then(function () %7B%0A%0A        Ember.Logger.info('Reverse relationships have been removed, proceeding to destroy %60' + contentTypeName + '%60');%0A%0A        // Remove search index info for type%0A        window.ENV.deleteTypeIndex(contentType.get('id'));%0A%0A        // remove all associated data from Firebase%0A        window.ENV.firebase.child('data').child(contentType.get('id')).remove(function () %7B%0A          Ember.Logger.info('Data for %60' + contentTypeName + '%60 has been destroyed.');%0A%0A  
     
@@ -2407,24 +2407,26 @@
 ontent type%0A
+  
         cont
@@ -2448,24 +2448,122 @@
 Record()
+.then(function () %7B%0A            Ember.Logger.info('%60' + contentTypeName + '%60 has been destroyed.')
 ;%0A      
 %7D%0A%0A    %7D
@@ -2550,26 +2550,54 @@
 d.');%0A      
+ 
-%7D%0A
+   %7D);%0A        %7D);%0A%0A      %7D);
 %0A    %7D,%0A    

remove reverse relation controls when deleting a content type.