webdav portal create new ability added

This commit is contained in:
vfedosevich 2015-03-11 05:34:35 -07:00
parent 6b1c1660fe
commit 50e902b94d
26 changed files with 473 additions and 38 deletions

View file

@ -1,5 +1,9 @@
function WspDialogs() {
this.settings = { dialogId: "#confirm-dialog", processDialogId: "#processDialog" };
this.settings = {
dialogId: "#confirm-dialog",
processDialogId: "#processDialog",
inlineProcessDialog: '.glyphicon-refresh'
};
}
WspDialogs.prototype =
@ -36,6 +40,14 @@ WspDialogs.prototype =
hideProcessDialog: function() {
$(this.settings.processDialogId).modal('hide');
}
},
showInlineProcessing: function(itemId) {
$(itemId).parent().find(this.settings.inlineProcessDialog).show();
},
hideInlineProcessing: function (itemId) {
$(itemId).parent().find(this.settings.inlineProcessDialog).hide();
}
};

View file

@ -2,8 +2,15 @@
this.settings = {
deletionBlockSelector: ".file-actions-menu .file-deletion",
deletionUrl: "storage/files-group-action/delete",
fileExistUrl: "storage/fileExist",
textDateModified: "Date modified",
textSize: "Size"
textSize: "Size",
textItemExist: "File already exists",
textItemExistFunc: function() {
return textItemExist;
} ,
createNewItemDialogId: "#createNewItemDialog",
createNewItemButtonId: "#create-button"
};
this.itemsTable = null;
this.searchTable = null;
@ -272,6 +279,38 @@ WspFileBrowser.prototype = {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
var i = Math.floor(Math.log(bytes) / Math.log(k));
return (bytes / Math.pow(k, i)).toPrecision(3) + ' ' + sizes[i];
},
showCreateNewItemDialog: function (extension, target) {
$(this.settings.createNewItemButtonId).data('extension', extension);
$(this.settings.createNewItemButtonId).data('target', target);
$(this.settings.createNewItemDialogId + " input").val("");
$(this.settings.createNewItemDialogId).modal();
},
hideCreateNewItemDialog: function () {
$(this.settings.createNewItemDialogId).modal('hide');
},
uniqueFileNameFieldRule: function(fieldId) {
return {
url: this.settings.fileExistUrl,
type: "post",
data: {
newItemName: function() {
return $(fieldId).val() + $(wsp.fileBrowser.settings.createNewItemButtonId).data('extension');
}
},
beforeSend: function(response) {
wsp.dialogs.showInlineProcessing(fieldId);
},
complete: function() {
wsp.dialogs.hideInlineProcessing(fieldId);
}
};
}
};

View file

@ -78,6 +78,132 @@ $('#drag-and-drop-area #file-input').click(function (e) {
});
$("#create-button").click(function (e) {
if ($('#filenameForm').valid()) {
var fileName = $('#createNewItemDialog #filename').val() + $(this).data('extension');
$(this).attr('href', $(this).data('href') + '/' + fileName);
$(this).attr('target', $(this).data('target'));
wsp.fileBrowser.hideCreateNewItemDialog();
//;
} else {
e.preventDefault();
}
});
$.fn.clearValidation = function () { var v = $(this).validate(); $('[name]', this).each(function () { v.successList.push(this); v.showErrors(); }); v.resetForm(); v.reset(); $(this).find('.form-group').removeClass('has-error'); };
$(document).ready(function() {
//bootstrap jquery validate styles fix
$.validator.setDefaults({
highlight: function(element) {
$(element).closest('.form-group').addClass('has-error');
},
unhighlight: function(element) {
$(element).closest('.form-group').removeClass('has-error');
},
errorElement: 'span',
errorClass: 'help-block',
errorPlacement: function(error, element) {
if (element.parent('.input-group').length) {
error.insertAfter(element.parent());
} else {
error.insertAfter(element);
}
}
});
$.validator.addMethod("synchronousRemote", function (value, element, param) {
if (this.optional(element)) {
return "dependency-mismatch";
}
var previous = this.previousValue(element);
if (!this.settings.messages[element.name]) {
this.settings.messages[element.name] = {};
}
previous.originalMessage = this.settings.messages[element.name].remote;
this.settings.messages[element.name].remote = previous.message;
param = typeof param === "string" && { url: param } || param;
if (previous.old === value) {
return previous.valid;
}
previous.old = value;
var validator = this;
this.startRequest(element);
var data = {};
data[element.name] = value;
var valid = "pending";
$.ajax($.extend(true, {
url: param,
async: false,
mode: "abort",
port: "validate" + element.name,
dataType: "json",
data: data,
success: function (response) {
validator.settings.messages[element.name].remote = previous.originalMessage;
valid = response === true || response === "true";
if (valid) {
var submitted = validator.formSubmitted;
validator.prepareElement(element);
validator.formSubmitted = submitted;
validator.successList.push(element);
delete validator.invalid[element.name];
validator.showErrors();
} else {
var errors = {};
var message = response || validator.defaultMessage(element, "remote");
errors[element.name] = previous.message = $.isFunction(message) ? message(value) : message;
validator.invalid[element.name] = true;
validator.showErrors(errors);
}
previous.valid = valid;
validator.stopRequest(element, valid);
}
}, param));
return valid;
}, "Please fix this field.");
$('#filenameForm').validate({
onkeyup: false,
onclick: false,
async: false,
rules: {
filename: {
required: true,
synchronousRemote: wsp.fileBrowser.uniqueFileNameFieldRule("#filename")
}
},
messages: {
filename: {
synchronousRemote: wsp.fileBrowser.settings.textItemExist
}
}
});
});
$(".create-new-item li a").click(function () {
$("#filenameForm").clearValidation();
wsp.fileBrowser.showCreateNewItemDialog($(this).data('extension'), $(this).data('target'));
$("#filename").focus();
});
function isMobileDevice() {
return (/android|webos|iphone|ipad|ipod|blackberry|iemobile|opera mini/i.test(navigator.userAgent.toLowerCase()));
}