Skip to content

Commit fcfb785

Browse files
committed
Merge branch 'NMC-533' of https://github.com/nextmcloud/server into fix/make_transfert_ownership_non_blocking
2 parents 2da4989 + d82bd97 commit fcfb785

File tree

4 files changed

+16
-149
lines changed

4 files changed

+16
-149
lines changed

apps/files/js/newfilemenu.js

Lines changed: 11 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@
5252
iconClass: 'icon-folder',
5353
fileType: 'folder',
5454
actionHandler: function(name) {
55-
self.fileList.createDirectory(name);
55+
const uniqueName = self.fileList.getUniqueName(name);
56+
let tempPromise = self.fileList.createDirectory(uniqueName);
57+
Promise.all([tempPromise]).then(() => {
58+
self.fileList.rename(uniqueName);
59+
});
5660
}
5761
}];
5862

@@ -90,102 +94,12 @@
9094

9195
_promptFileName: function($target) {
9296
var self = this;
93-
94-
if ($target.find('form').length) {
95-
$target.find('input[type=\'text\']').focus();
96-
return;
97-
}
98-
99-
// discard other forms
100-
this.$el.find('form').remove();
101-
this.$el.find('.displayname').removeClass('hidden');
102-
103-
$target.find('.displayname').addClass('hidden');
104-
105-
var newName = $target.attr('data-templatename');
106-
var fileType = $target.attr('data-filetype');
107-
var $form = $(OCA.Files.Templates['newfilemenu_filename_form']({
108-
fileName: newName,
109-
cid: this.cid,
110-
fileType: fileType
111-
}));
112-
113-
//this.trigger('actionPerformed', action);
114-
$target.append($form);
115-
116-
// here comes the OLD code
117-
var $input = $form.find('input[type=\'text\']');
118-
var $submit = $form.find('input[type=\'submit\']');
119-
120-
var lastPos;
121-
var checkInput = function () {
122-
// Special handling for the setup template directory
123-
if ($target.attr('data-action') === 'template-init') {
124-
return true;
125-
}
126-
127-
var filename = $input.val();
128-
try {
129-
if (!Files.isFileNameValid(filename)) {
130-
// Files.isFileNameValid(filename) throws an exception itself
131-
} else if (self.fileList.inList(filename)) {
132-
throw t('files', '{newName} already exists', {newName: filename}, undefined, {
133-
escape: false
134-
});
135-
} else {
136-
return true;
137-
}
138-
} catch (error) {
139-
$input.attr('title', error);
140-
$input.tooltip({placement: 'right', trigger: 'manual', 'container': '.newFileMenu'});
141-
$input.tooltip('fixTitle');
142-
$input.tooltip('show');
143-
$input.addClass('error');
144-
}
145-
return false;
146-
};
147-
148-
// verify filename on typing
149-
$input.keyup(function() {
150-
if (checkInput()) {
151-
$input.tooltip('hide');
152-
$input.removeClass('error');
153-
}
154-
});
155-
156-
$submit.click(function(event) {
157-
event.stopPropagation();
158-
event.preventDefault();
159-
$form.submit();
160-
});
161-
162-
$input.focus();
163-
// pre select name up to the extension
164-
lastPos = newName.lastIndexOf('.');
165-
if (lastPos === -1) {
166-
lastPos = newName.length;
167-
}
168-
$input.selectRange(0, lastPos);
169-
170-
$form.submit(function(event) {
171-
event.stopPropagation();
172-
event.preventDefault();
173-
174-
if (checkInput()) {
175-
var newname = $input.val().trim();
176-
177-
/* Find the right actionHandler that should be called.
178-
* Actions is retrieved by using `actionSpec.id` */
179-
var action = _.filter(self._menuItems, function(item) {
180-
return item.id == $target.attr('data-action');
181-
}).pop();
182-
action.actionHandler(newname);
183-
184-
$form.remove();
185-
$target.find('.displayname').removeClass('hidden');
186-
OC.hideMenus();
187-
}
188-
});
97+
var newname = $target.attr('data-templatename');
98+
var action = _.filter(self._menuItems, function(item) {
99+
return item.id == $target.attr('data-action');
100+
}).pop();
101+
action.actionHandler(newname);
102+
OC.hideMenus();
189103
},
190104

191105
/**

apps/files/src/templates.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ templates.forEach((provider, index) => {
110110
iconClass: provider.iconClass || 'icon-file',
111111
fileType: 'file',
112112
actionHandler(name) {
113-
TemplatePicker.open(name, provider)
113+
const fileName = FileList.getUniqueName(name)
114+
TemplatePicker.open(fileName, provider)
114115
},
115116
})
116117
},

apps/files/src/views/TemplatePicker.vue

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -214,17 +214,7 @@ export default {
214214
this.logger.debug('Created new file', fileInfo)
215215
216216
await fileList?.addAndFetchFileInfo(this.name)
217-
218-
// Run default action
219-
const fileAction = OCA.Files.fileActions.getDefaultFileAction(fileInfo.mime, 'file', OC.PERMISSION_ALL)
220-
fileAction.action(fileInfo.basename, {
221-
$file: fileList?.findFileEl(this.name),
222-
dir: currentDirectory,
223-
fileList,
224-
fileActions: fileList?.fileActions,
225-
fileInfoModel: fileList?.getModelForFile(this.name),
226-
})
227-
217+
fileList.rename(this.name)
228218
this.close()
229219
} catch (error) {
230220
this.logger.error('Error while creating the new file from template')

apps/files/tests/js/newfilemenuSpec.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -62,41 +62,13 @@ describe('OCA.Files.NewFileMenu', function() {
6262
beforeEach(function() {
6363
createDirectoryStub = sinon.stub(FileList.prototype, 'createDirectory');
6464
menu.$el.find('.menuitem').eq(1).click();
65-
$input = menu.$el.find('form.filenameform input');
6665
});
6766
afterEach(function() {
6867
createDirectoryStub.restore();
6968
});
7069

71-
it('sets default text in field', function() {
72-
// text + submit
73-
expect($input.length).toEqual(2);
74-
expect($input.val()).toEqual('New folder');
75-
});
76-
it('prevents entering invalid file names', function() {
77-
$input.val('..');
78-
$input.trigger(new $.Event('keyup', {keyCode: 13}));
79-
$input.closest('form').submit();
80-
81-
expect(createDirectoryStub.notCalled).toEqual(true);
82-
});
83-
it('prevents entering file names that already exist', function() {
84-
var inListStub = sinon.stub(fileList, 'inList').returns(true);
85-
$input.val('existing.txt');
86-
$input.trigger(new $.Event('keyup', {keyCode: 13}));
87-
$input.closest('form').submit();
88-
89-
expect(createDirectoryStub.notCalled).toEqual(true);
90-
inListStub.restore();
91-
});
9270
it('creates directory when clicking on create directory field', function() {
93-
$input = menu.$el.find('form.filenameform input');
94-
$input.val('some folder');
95-
$input.trigger(new $.Event('keyup', {keyCode: 13}));
96-
$input.closest('form').submit();
97-
98-
expect(createDirectoryStub.calledOnce).toEqual(true);
99-
expect(createDirectoryStub.getCall(0).args[0]).toEqual('some folder');
71+
expect(createDirectoryStub.getCall(0).args[0]).toEqual('New folder');
10072
});
10173
});
10274
describe('custom entries', function() {
@@ -135,17 +107,7 @@ describe('OCA.Files.NewFileMenu', function() {
135107
});
136108
it('calls action handler when clicking on custom item', function() {
137109
menu.$el.find('.menuitem').eq(2).click();
138-
var $input = menu.$el.find('form.filenameform input');
139-
$input.val('some name');
140-
$input.trigger(new $.Event('keyup', {keyCode: 13}));
141-
$input.closest('form').submit();
142-
143-
expect(actionStub.calledOnce).toEqual(true);
144-
expect(actionStub.getCall(0).args[0]).toEqual('some name');
145-
});
146-
it('switching fields removes the previous form', function() {
147-
menu.$el.find('.menuitem').eq(2).click();
148-
expect(menu.$el.find('form').length).toEqual(1);
110+
expect(actionStub.getCall(0).args[0]).toEqual('New text file.txt');
149111
});
150112
});
151113
});

0 commit comments

Comments
 (0)