|
|
|
@ -18,14 +18,15 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
"click ul > li > a.radiobutton" : "_changeOption",
|
|
|
|
|
'click div.url p' : "_activateTextInput",
|
|
|
|
|
'keyup input[type="text"]' : "_onInputChange",
|
|
|
|
|
'keypress input[type="text"]' : "_onKeyPress"
|
|
|
|
|
'submit form' : "_onSubmitForm"
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize: function() {
|
|
|
|
|
|
|
|
|
|
// We need "this" in these functions
|
|
|
|
|
_.bindAll(this, "_activateTextInput", "_createTable", "_onUploadError", "_onUploadSubmit", "_onUploadProgress", "_onUploadCancel", "_onUploadAdd", "_onUploadComplete", "_changeOption", "_checkOptions");
|
|
|
|
|
_.bindAll(this, "_activateTextInput", "_createTable", "_onUploadError", "_onUploadSubmit", "_onUploadProgress",
|
|
|
|
|
"_onUploadDragOver", "_onUploadCancel", "_onUploadAdd", "_onUploadComplete", "_changeOption", "_checkOptions");
|
|
|
|
|
|
|
|
|
|
// Option selected by default
|
|
|
|
|
this.option = 0;
|
|
|
|
@ -90,7 +91,9 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
autoUpload: true,
|
|
|
|
|
add: this._onUploadAdd,
|
|
|
|
|
acceptFileTypes: this.options.acceptFileTypes,
|
|
|
|
|
//start: this._onUploadSubmit,
|
|
|
|
|
submit: this._onUploadSubmit,
|
|
|
|
|
drop: this._onDrop,
|
|
|
|
|
dragover: this._onUploadDragOver,
|
|
|
|
|
progress: this._onUploadProgress,
|
|
|
|
|
stop: this._onUploadCancel,
|
|
|
|
|
done: this._onUploadComplete,
|
|
|
|
@ -132,7 +135,10 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
this._checkOptions();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onKeyPress: function(ev) {
|
|
|
|
|
_onSubmitForm: function(ev) {
|
|
|
|
|
ev.preventDefault();
|
|
|
|
|
ev.stopPropagation();
|
|
|
|
|
|
|
|
|
|
var code = (ev.keyCode ? ev.keyCode : ev.which);
|
|
|
|
|
if(code == 13) { //Enter keycode
|
|
|
|
|
this.$el.find("a.ok").click();
|
|
|
|
@ -188,34 +194,39 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Uploader functions */
|
|
|
|
|
_onUploadSubmit: function(id,fileName) {
|
|
|
|
|
console.log("submit?");
|
|
|
|
|
_onUploadSubmit: function(ev,data) {
|
|
|
|
|
console.log("uploading");
|
|
|
|
|
this._changeState("uploading");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onUploadProgress: function(id, fileName, loaded, total) {
|
|
|
|
|
_onUploadProgress: function(ev,data) {
|
|
|
|
|
console.log("progress?");
|
|
|
|
|
var loaded = data.loaded
|
|
|
|
|
, total = data.total;
|
|
|
|
|
|
|
|
|
|
var percentage = (loaded / total) * 100;
|
|
|
|
|
this.$content
|
|
|
|
|
.find("div.progress span")
|
|
|
|
|
.width(percentage + "%");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onUploadCancel: function(id, fileName) {
|
|
|
|
|
_onUploadCancel: function(ev,data) {
|
|
|
|
|
console.log("cancel?");
|
|
|
|
|
this._changeState("reset");
|
|
|
|
|
// console.log(id,fileName);
|
|
|
|
|
// if (id.result) {
|
|
|
|
|
// this._changeState("reset");
|
|
|
|
|
// }
|
|
|
|
|
//this._changeState("reset");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onUploadComplete: function(id, fileName, responseJSON) {
|
|
|
|
|
console.log("importing?");
|
|
|
|
|
_onUploadComplete: function(ev,data) {
|
|
|
|
|
this._changeState("importing");
|
|
|
|
|
this._importTable(fileName,responseJSON.file_uri)
|
|
|
|
|
//this._importTable(fileName,responseJSON.file_uri)
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
_onUploadError: function(ev,fileupload) {
|
|
|
|
|
console.log("error?");
|
|
|
|
|
var filename = fileupload.files[0].name
|
|
|
|
|
, error_type = fileupload.files[0].error
|
|
|
|
|
_onUploadError: function(ev,data) {
|
|
|
|
|
var filename = data.files[0].name
|
|
|
|
|
, error_type = data.files[0].error
|
|
|
|
|
, msg = this.options.error_messages[error_type].replace("{filename}", filename);
|
|
|
|
|
|
|
|
|
|
this.$content
|
|
|
|
@ -230,6 +241,29 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_onUploadDragOver: function() {
|
|
|
|
|
console.log("TODO -> SHOW THE CLASS!");
|
|
|
|
|
this.$upload.addClass("drop");
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Import table from a url
|
|
|
|
|
_importTable: function(fileName,file_uri) {
|
|
|
|
|
|
|
|
|
@ -330,14 +364,15 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_changeState: function(mode) {
|
|
|
|
|
console.log("changeState" + ":" + mode);
|
|
|
|
|
|
|
|
|
|
/* Change scenario depending on the app mode */
|
|
|
|
|
switch (mode) {
|
|
|
|
|
case "reset":
|
|
|
|
|
// Remove additional and error info
|
|
|
|
|
// this.$importation
|
|
|
|
|
// .find("div.info")
|
|
|
|
|
// .removeClass("active");
|
|
|
|
|
this.$importation
|
|
|
|
|
.find("div.info")
|
|
|
|
|
.removeClass("active");
|
|
|
|
|
|
|
|
|
|
// Change title
|
|
|
|
|
this.$importation
|
|
|
|
@ -465,11 +500,14 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
this.$loader.find("p").text("Uploading your table...");
|
|
|
|
|
|
|
|
|
|
this.$loader
|
|
|
|
|
.animate({
|
|
|
|
|
top: pos.top + "px"
|
|
|
|
|
},500)
|
|
|
|
|
.css({top: '40px', opacity: '0'})
|
|
|
|
|
.removeClass("creating")
|
|
|
|
|
.addClass("uploading")
|
|
|
|
|
.animate({
|
|
|
|
|
opacity: 1,
|
|
|
|
|
top: pos.top
|
|
|
|
|
},1000)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Show the loader
|
|
|
|
|
this._showLoader();
|
|
|
|
@ -628,6 +666,8 @@ cdb.admin.CreateTableDialog = cdb.ui.common.Dialog.extend({
|
|
|
|
|
* Reclean some custom bindings
|
|
|
|
|
*/
|
|
|
|
|
_reClean: function() {
|
|
|
|
|
this.$upload.fileupload("destroy")
|
|
|
|
|
// Cancel upload
|
|
|
|
|
// TODO //
|
|
|
|
|
this.$upload.fileupload("destroy");
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|