FM.MainController = function () {
  return {
    set_areas: function (area_1, area_2) {
      this.area_1 = area_1;
      this.area_2 = area_2;
    },

    update: function () {
      this.area_1.Controller.index();
      this.area_2.Controller.index();
    },

    with_buffer: function () {
      return !!this.buffer_items;
    },

    cut: function (items) {
      this.buffer_type = 'cut';
      this.buffer_items = items;
    },

    copy: function (items) {
      this.buffer_type = 'copy';
      this.buffer_items = items;
    },

    paste: function (path) {
      var self = this;

      $.each(this.buffer_items, function (i, item) {
        var new_item_path = path + '/' + item.name;

        if (self.buffer_type == 'cut') {
          $.ajax({
            url: '/move/' +
                 encodeURIComponent(item.path) +
                 '/' +
                 encodeURIComponent(new_item_path),
            type: 'POST',
            async: false,
          });
        }

        if (self.buffer_type == 'copy') {
          $.ajax({
            url: '/copy/' +
                 encodeURIComponent(item.path) +
                 '/' +
                 encodeURIComponent(new_item_path),
            type: 'POST',
            async: false,
          });
        }
      });

      this.buffer_type = undefined;
      this.buffer_items = undefined;

      this.update();
    },

    delete: function (items) {
      var self = this;

      Message.confirm({
        title: 'Delete',
        content: 'Are you sure?',
        callback: function (response) {
          if (response) {
            $.each(items, function (i, item) {
              $.ajax({
                url: '/remove/' + encodeURIComponent(item.path),
                type: 'POST',
                async: false,
              });
            });

            self.update();
          }
        }
      });
    },

    rename: function (item) {
      var self = this;

      Message.prompt({
        title: 'Rename',
        content: 'Enter the new name',
        callback: function (response) {
          if (response) {
            $.ajax({
              url: '/rename/' +
                   encodeURIComponent(item.path) +
                   '/' +
                   encodeURIComponent(response),
              type: 'POST',
              async: false,
            });

            self.update();
          }
        },
        value: item.name
      });
    },

    zip: function (item) {
      var self = this;

      Message.prompt({
        title: 'Zip',
        content: 'Enter the zip name',
        callback: function (response) {
          if (response) {
            $.ajax({
              url: '/zip/' +
                   encodeURIComponent(item.path) +
                   '/' +
                   encodeURIComponent(response),
              type: 'POST',
              async: false,
            });

            self.update();
          }
        },
        value: item.name
      });
    },

    unzip: function (item) {
      var self = this;

      Message.prompt({
        title: 'Unzip',
        content: 'Enter the directory name',
        callback: function (response) {
          if (response) {
            $.ajax({
              url: '/unzip/' +
                   encodeURIComponent(item.path) +
                   '/' +
                   encodeURIComponent(response),
              type: 'POST',
              async: false,
            });

            self.update();
          }
        },
        value: item.name.replace('.zip', '')
      });
    },

    download: function (item) {
      window.open('/download/' + encodeURIComponent(item.path));
      this.update();
    },

    mkdir: function (path) {
      var self = this;

      Message.prompt({
        title: 'New directory',
        content: 'Enter the directory name',
        callback: function (response) {
          if (response) {
            $.ajax({
              url: '/mkdir/' + encodeURIComponent(path + '/' + response),
              type: 'POST',
              async: false,
            });

            self.update();
          }
        },
        value: 'New directory'
      });
    }
  };
};


@@ -937,37 +937,179 @@
             
-async: false,
+success: function () %7B%0A              self.buffer_type = undefined;%0A              self.buffer_items = undefined;%0A%0A              self.update();%0A            %7D
 %0A          %7D
@@ -1377,35 +1377,30 @@
     
-async: false,%0A          %7D);
+success: function () %7B
 %0A   
@@ -1408,31 +1408,18 @@
     
-%7D%0A
       
-%7D);%0A%0A      this
+self
 .buf
@@ -1438,36 +1438,44 @@
 ndefined;%0A      
-this
+        self
 .buffer_items = 
@@ -1488,36 +1488,92 @@
 ned;%0A%0A      
-this.update(
+        self.update();%0A            %7D%0A          %7D);%0A        %7D%0A      %7D
 );%0A    %7D,%0A%0A 
@@ -1952,37 +1952,97 @@
             
-async: false,
+success: function () %7B%0A                  self.update();%0A                %7D
 %0A           
@@ -2067,36 +2067,8 @@
  %7D);
-%0A%0A            self.update();
 %0A   
@@ -2535,39 +2535,37 @@
     
-async: false,%0A      
+success: function () %7B%0A
       
-%7D);%0A%0A
     
@@ -2562,34 +2562,32 @@
                 
-  
 self.update();%0A 
@@ -2577,32 +2577,64 @@
  self.update();%0A
+              %7D%0A            %7D);%0A
           %7D%0A    
@@ -3105,39 +3105,37 @@
     
-async: false,%0A      
+success: function () %7B%0A
       
-%7D);%0A%0A
     
@@ -3132,34 +3132,32 @@
                 
-  
 self.update();%0A 
@@ -3147,32 +3147,64 @@
  self.update();%0A
+              %7D%0A            %7D);%0A
           %7D%0A    
@@ -3687,39 +3687,37 @@
     
-async: false,%0A      
+success: function () %7B%0A
       
-%7D);%0A%0A
     
@@ -3714,34 +3714,32 @@
                 
-  
 self.update();%0A 
@@ -3729,32 +3729,64 @@
  self.update();%0A
+              %7D%0A            %7D);%0A
           %7D%0A    
@@ -4341,39 +4341,37 @@
     
-async: false,%0A      
+success: function () %7B%0A
       
-%7D);%0A%0A
     
@@ -4368,34 +4368,32 @@
                 
-  
 self.update();%0A 
@@ -4383,32 +4383,64 @@
  self.update();%0A
+              %7D%0A            %7D);%0A
           %7D%0A    

switch to async in main_controller