Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NMC-533 Set new folder name inline #28645

Closed
wants to merge 9 commits into from
108 changes: 11 additions & 97 deletions apps/files/js/newfilemenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@
iconClass: 'icon-folder',
fileType: 'folder',
actionHandler: function(name) {
self.fileList.createDirectory(name);
const uniqueName = self.fileList.getUniqueName(name);
let tempPromise = self.fileList.createDirectory(uniqueName);
Promise.all([tempPromise]).then(() => {
self.fileList.rename(uniqueName);
});
}
}];
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -90,102 +94,12 @@

_promptFileName: function($target) {
var self = this;

if ($target.find('form').length) {
$target.find('input[type=\'text\']').focus();
return;
}

// discard other forms
this.$el.find('form').remove();
this.$el.find('.displayname').removeClass('hidden');

$target.find('.displayname').addClass('hidden');

var newName = $target.attr('data-templatename');
var fileType = $target.attr('data-filetype');
var $form = $(OCA.Files.Templates['newfilemenu_filename_form']({
fileName: newName,
cid: this.cid,
fileType: fileType
}));

//this.trigger('actionPerformed', action);
$target.append($form);

// here comes the OLD code
var $input = $form.find('input[type=\'text\']');
var $submit = $form.find('input[type=\'submit\']');

var lastPos;
var checkInput = function () {
// Special handling for the setup template directory
if ($target.attr('data-action') === 'template-init') {
return true;
}

var filename = $input.val();
try {
if (!Files.isFileNameValid(filename)) {
// Files.isFileNameValid(filename) throws an exception itself
} else if (self.fileList.inList(filename)) {
throw t('files', '{newName} already exists', {newName: filename}, undefined, {
escape: false
});
} else {
return true;
}
} catch (error) {
$input.attr('title', error);
$input.tooltip({placement: 'right', trigger: 'manual', 'container': '.newFileMenu'});
$input.tooltip('fixTitle');
$input.tooltip('show');
$input.addClass('error');
}
return false;
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved
};

// verify filename on typing
$input.keyup(function() {
if (checkInput()) {
$input.tooltip('hide');
$input.removeClass('error');
}
});

$submit.click(function(event) {
event.stopPropagation();
event.preventDefault();
$form.submit();
});

$input.focus();
// pre select name up to the extension
lastPos = newName.lastIndexOf('.');
if (lastPos === -1) {
lastPos = newName.length;
}
$input.selectRange(0, lastPos);

$form.submit(function(event) {
event.stopPropagation();
event.preventDefault();

if (checkInput()) {
var newname = $input.val().trim();

/* Find the right actionHandler that should be called.
* Actions is retrieved by using `actionSpec.id` */
var action = _.filter(self._menuItems, function(item) {
return item.id == $target.attr('data-action');
}).pop();
action.actionHandler(newname);

$form.remove();
$target.find('.displayname').removeClass('hidden');
OC.hideMenus();
}
});
var newname = $target.attr('data-templatename');
var action = _.filter(self._menuItems, function(item) {
return item.id == $target.attr('data-action');
}).pop();
action.actionHandler(newname);
OC.hideMenus();
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved
},

/**
Expand Down
12 changes: 1 addition & 11 deletions apps/files/src/views/TemplatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,7 @@ export default {
this.logger.debug('Created new file', fileInfo)

await fileList?.addAndFetchFileInfo(this.name)

// Run default action
const fileAction = OCA.Files.fileActions.getDefaultFileAction(fileInfo.mime, 'file', OC.PERMISSION_ALL)
fileAction.action(fileInfo.basename, {
$file: fileList?.findFileEl(this.name),
dir: currentDirectory,
fileList,
fileActions: fileList?.fileActions,
fileInfoModel: fileList?.getModelForFile(this.name),
})

fileList.rename(this.name);
skjnldsv marked this conversation as resolved.
Show resolved Hide resolved
this.close()
} catch (error) {
this.logger.error('Error while creating the new file from template')
Expand Down