<commit_before>
  /*
   *  Dialog to import new files to CartoDB.
   *
   *  - It doesn't need any model, just the user quota.
   *  - You can attach any file (from mamufas) or an ur (from for example)
   *  the common data.
   *  - It creates a model to control the state of the dialog:
   *   · State: what is doing the dialog -> (idle, uploading, importing or error)
   *   · Option: option clicked -> (file or scratch, for the moment)
   *
   *  
   *  new cdb.admin.CreateTableDialog({
   *    tables: new cdb.admin.Tables(),
   *    files: files,
   *    url: url,
   *    quota: user_quota
   *  });
   *
   */


  cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({

    _TEXTS: {
      title:      _t("New table"),
      ok: {
        normal:   _t("Create table"),
        empty:    _t("Create empty table")
      },
      error: {
        default:  _t('Ooops, there was an error in the importation, please try again.'),
        sorry:    _t('Sorry, something went wrong and we\'re not sure what. Contact us at \
                      <a href="mailto:<EMAIL>"><EMAIL></a>.'),
        unknown:  _t('Unknown')
      }
    },

    events: function(){
      return _.extend({},cdb.ui.common.Dialog.prototype.events,{
        'click .dialog-tab > a':          '_optionClicked',
        'click .upload-progress a.stop':  '_onUploadAbort'
      });
    },

    _UPLOADER: {
      url:              '/api/v1/imports',
      maxFileSize:      100000000,
      maxUploadFiles:   1,
      acceptFileTypes:  /(\.|\/)(csv|xlsx?|zip|kml|geojson|json|ods|kmz|gpx|tar|gz|tgz|osm|bz2|tif|tiff|txt)$/i
    },

    initialize: function() {
      _.bindAll(this, "_onUploadProgress", "_onUploadStart", "_onUploadAbort",
        "_onUploadAdd", "_onUploadComplete", "_keydown");

      // Extend options
      _.extend(this.options, {
        title: this._TEXTS.title,
        description: '',
        template_name: 'common/views/create_dialog_base',
        clean_on_hide: true,
        ok_button_classes: "button green disabled",
        ok_title: this._TEXTS.ok.normal,
        ok_title_empty: this._TEXTS.ok.empty,
        modal_type: "creation",
        width: 600
      });

      // Create a model to know the options clicked
      // and the state of the dialog
      this.model = new cdb.core.Model({
        option: 'file',
        state:  'idle'
      });

      this.model.bind('change:option', this._onOptionChange, this);

      // Super!
      this.constructor.__super__.initialize.apply(this);
    },


    //////////////
    //  RENDER  //
    //////////////

    render_content: function() {
      var $content = this.$content = $("<div>");
      this.temp_content = cdb.templates.getTemplate('common/views/create_dialog_content');
      $content.append(this.temp_content());

      // Render file tabs
      this.render_upload_tabs($content);

      // Init uploader
      this._init_uploader($content);

      return $content;
    },

    render_upload_tabs: function($content) {
      // Upload tabs
      this.upload_tabs = new cdb.admin.Tabs({
        el: $content.find('.upload-tabs'),
        slash: true
      });
      this.addView(this.upload_tabs);

      // File pane
      this.filePane = new cdb.admin.ImportFilePane({
        maxFileSize: this.options.quota,
        maxUploadFiles: this._UPLOADER.maxUploadFiles,
        acceptFileTypes: this._UPLOADER.acceptFileTypes
      });
      this.filePane.bind('fileChosen', this._uploadData, this);
      this.filePane.bind('inputChange', this._checkOKButton, this);

      // GDrive
      // this.gdrivePane = new cdb.admin.ImportGdrivePane();
      // this.gdrivePane.bind('fileChosen', this._uploadData, this);

      // Dropbox
      this.dropboxPane = new cdb.admin.ImportDropboxPane();
      this.dropboxPane.bind('fileChosen', this._uploadData, this);

      // Create TabPane
      this.upload_panes = new cdb.ui.common.TabPane({
        el: $content.find(".upload-panes")
      });
      this.upload_panes.addTab('file', this.filePane);
      // this.upload_panes.addTab('gdrive', this.gdrivePane);
      this.upload_panes.addTab('dropbox', this.dropboxPane);
      this.upload_panes.bind('tabEnabled', this._checkOKButton, this);

      this.upload_tabs.linkToPanel(this.upload_panes);
      this.addView(this.upload_panes);
      $content.append(this.upload_panes.render());

      this.upload_panes.active('file');
    },



    ////////////////////////
    //  UPLOADER ACTIONS  //
    ////////////////////////

    // Create uploader
    _init_uploader: function($content) {
      // Create all components vars
      this.$loader      = $content.find("div.upload-progress");
      this.$list        = $content.find("div.dialog-content");
      this.$import      = $content.find("div.upload");
      this.$error       = this.$("section.modal.error");
      this.$importation = this.$("section.modal:eq(0)");

      // Create the fileupload
      var $upload = this.$upload = $content.find("form.dialog-uploader");
      $upload.fileupload({
        // It is not possible to disable dropzone.
        // So, dropzone element doesn't exist, :)
        dropZone:               this.$('.non-dropzone'),
        url:                    this._UPLOADER.url,
        paramName:              'filename',
        progressInterval:       100,
        bitrateInterval:        500,
        maxFileSize:            this._UPLOADER.maxFileSize,
        autoUpload:             true,
        limitMultiFileUploads:  this._UPLOADER.maxUploadFiles,
        limitConcurrentUploads: this._UPLOADER.maxUploadFiles,
        add:                    this._onUploadAdd,
        progress:               this._onUploadProgress,
        start:                  this._onUploadStart,
        done:                   this._onUploadComplete,
        fail:                   this._onUploadError
      });

      // Hide importation error
      this.$error.hide();

      // Have you dropped a file in the big mamufas?
      this._checkFiles();

      return this.$content;
    },


    // Check if any file has been dropped with big mamufas
    // or started with an url link.
    _checkFiles: function() {<commit_msg>CDB-245 #resolve - fixed problem when drop an unsupported file type<commit_after>
  /*
   *  Dialog to import new files to CartoDB.
   *
   *  - It doesn't need any model, just the user quota.
   *  - You can attach any file (from mamufas) or an ur (from for example)
   *  the common data.
   *  - It creates a model to control the state of the dialog:
   *   · State: what is doing the dialog -> (idle, uploading, importing or error)
   *   · Option: option clicked -> (file or scratch, for the moment)
   *
   *  
   *  new cdb.admin.CreateTableDialog({
   *    tables: new cdb.admin.Tables(),
   *    files: files,
   *    url: url,
   *    quota: user_quota
   *  });
   *
   */


  cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({

    _TEXTS: {
      title:      _t("New table"),
      ok: {
        normal:   _t("Create table"),
        empty:    _t("Create empty table")
      },
      error: {
        default:  _t('Ooops, there was an error in the importation, please try again.'),
        sorry:    _t('Sorry, something went wrong and we\'re not sure what. Contact us at \
                      <a href="mailto:<EMAIL>"><EMAIL></a>.'),
        unknown:  _t('Unknown')
      }
    },

    events: function(){
      return _.extend({},cdb.ui.common.Dialog.prototype.events,{
        'click .dialog-tab > a':          '_optionClicked',
        'click .upload-progress a.stop':  '_onUploadAbort'
      });
    },

    _UPLOADER: {
      url:              '/api/v1/imports',
      maxFileSize:      100000000,
      maxUploadFiles:   1,
      acceptFileTypes:  /(\.|\/)(csv|xlsx?|zip|kml|geojson|json|ods|kmz|gpx|tar|gz|tgz|osm|bz2|tif|tiff|txt)$/i
    },

    initialize: function() {
      _.bindAll(this, "_onUploadProgress", "_onUploadStart", "_onUploadAbort",
        "_onUploadAdd", "_onUploadComplete", "_onUploadError", "_keydown");

      // Extend options
      _.extend(this.options, {
        title: this._TEXTS.title,
        description: '',
        template_name: 'common/views/create_dialog_base',
        clean_on_hide: true,
        ok_button_classes: "button green disabled",
        ok_title: this._TEXTS.ok.normal,
        ok_title_empty: this._TEXTS.ok.empty,
        modal_type: "creation",
        width: 600
      });

      // Create a model to know the options clicked
      // and the state of the dialog
      this.model = new cdb.core.Model({
        option: 'file',
        state:  'idle'
      });

      this.model.bind('change:option', this._onOptionChange, this);

      // Super!
      this.constructor.__super__.initialize.apply(this);
    },


    //////////////
    //  RENDER  //
    //////////////

    render_content: function() {
      var $content = this.$content = $("<div>");
      this.temp_content = cdb.templates.getTemplate('common/views/create_dialog_content');
      $content.append(this.temp_content());

      // Render file tabs
      this.render_upload_tabs($content);

      // Init uploader
      this._init_uploader($content);

      return $content;
    },

    render_upload_tabs: function($content) {
      // Upload tabs
      this.upload_tabs = new cdb.admin.Tabs({
        el: $content.find('.upload-tabs'),
        slash: true
      });
      this.addView(this.upload_tabs);

      // File pane
      this.filePane = new cdb.admin.ImportFilePane({
        maxFileSize: this.options.quota,
        maxUploadFiles: this._UPLOADER.maxUploadFiles,
        acceptFileTypes: this._UPLOADER.acceptFileTypes
      });
      this.filePane.bind('fileChosen', this._uploadData, this);
      this.filePane.bind('inputChange', this._checkOKButton, this);

      // GDrive
      // this.gdrivePane = new cdb.admin.ImportGdrivePane();
      // this.gdrivePane.bind('fileChosen', this._uploadData, this);

      // Dropbox
      this.dropboxPane = new cdb.admin.ImportDropboxPane();
      this.dropboxPane.bind('fileChosen', this._uploadData, this);

      // Create TabPane
      this.upload_panes = new cdb.ui.common.TabPane({
        el: $content.find(".upload-panes")
      });
      this.upload_panes.addTab('file', this.filePane);
      // this.upload_panes.addTab('gdrive', this.gdrivePane);
      this.upload_panes.addTab('dropbox', this.dropboxPane);
      this.upload_panes.bind('tabEnabled', this._checkOKButton, this);

      this.upload_tabs.linkToPanel(this.upload_panes);
      this.addView(this.upload_panes);
      $content.append(this.upload_panes.render());

      this.upload_panes.active('file');
    },



    ////////////////////////
    //  UPLOADER ACTIONS  //
    ////////////////////////

    // Create uploader
    _init_uploader: function($content) {
      // Create all components vars
      this.$loader      = $content.find("div.upload-progress");
      this.$list        = $content.find("div.dialog-content");
      this.$import      = $content.find("div.upload");
      this.$error       = this.$("section.modal.error");
      this.$importation = this.$("section.modal:eq(0)");

      // Create the fileupload
      var $upload = this.$upload = $content.find("form.dialog-uploader");
      $upload.fileupload({
        // It is not possible to disable dropzone.
        // So, dropzone element doesn't exist, :)
        dropZone:               this.$('.non-dropzone'),
        url:                    this._UPLOADER.url,
        paramName:              'filename',
        progressInterval:       100,
        bitrateInterval:        500,
        maxFileSize:            this._UPLOADER.maxFileSize,
        autoUpload:             true,
        limitMultiFileUploads:  this._UPLOADER.maxUploadFiles,
        limitConcurrentUploads: this._UPLOADER.maxUploadFiles,
        acceptFileTypes:        this._UPLOADER.acceptFileTypes,
        add:                    this._onUploadAdd,
        progress:               this._onUploadProgress,
        start:                  this._onUploadStart,
        done:                   this._onUploadComplete,
        fail:                   this._onUploadError
      });

      // Hide importation error
      this.$error.hide();

      // Have you dropped a file in the big mamufas?
      this._checkFiles();

      return this.$content;
    },


    // Check if any file has been dropped with big mamufas
    // or started with an url link.
    _checkFiles: function() {
{'fraction_non_alphanumeric': 0.13990384615384616, 'fraction_numerical': 0.003766025641025641, 'mean_word_length': 2.043404047793221, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2366289', 'n_tokens_mistral': 3852, 'n_tokens_neox': 3756, 'n_words': 778}