|
53 | 53 | fileType: 'folder', |
54 | 54 | actionLabel: t('files', 'Create new folder'), |
55 | 55 | actionHandler: function(name) { |
56 | | - self.fileList.createDirectory(name); |
| 56 | + const uniqueName = self.fileList.getUniqueName(name) |
| 57 | + let tempPromise = self.fileList.createDirectory(uniqueName, { showDetailsView: false }) |
| 58 | + Promise.all([tempPromise]).then(() => { |
| 59 | + self.fileList.rename(uniqueName) |
| 60 | + }) |
57 | 61 | } |
58 | 62 | }]; |
59 | 63 |
|
|
99 | 103 |
|
100 | 104 | _promptFileName: function($target) { |
101 | 105 | var self = this; |
102 | | - |
103 | | - if ($target.find('form').length) { |
104 | | - $target.find('input[type=\'text\']').focus(); |
105 | | - return; |
106 | | - } |
107 | | - |
108 | | - // discard other forms |
109 | | - this.$el.find('form').remove(); |
110 | | - this.$el.find('.displayname').removeClass('hidden'); |
111 | | - |
112 | | - $target.find('.displayname').addClass('hidden'); |
113 | | - |
114 | | - var newName = $target.attr('data-templatename'); |
115 | | - var fileType = $target.attr('data-filetype'); |
116 | | - var actionLabel = $target.attr('data-action-label'); |
117 | | - var $form = $(OCA.Files.Templates['newfilemenu_filename_form']({ |
118 | | - fileName: newName, |
119 | | - cid: this.cid, |
120 | | - fileType: fileType, |
121 | | - actionLabel, |
122 | | - })); |
123 | | - |
124 | | - //this.trigger('actionPerformed', action); |
125 | | - $target.append($form); |
126 | | - |
127 | | - // here comes the OLD code |
128 | | - var $input = $form.find('input[type=\'text\']'); |
129 | | - var $submit = $form.find('input[type=\'submit\']'); |
130 | | - |
131 | | - var lastPos; |
132 | | - var checkInput = function () { |
133 | | - // Special handling for the setup template directory |
134 | | - if ($target.attr('data-action') === 'template-init') { |
135 | | - return true; |
136 | | - } |
137 | | - |
138 | | - var filename = $input.val(); |
139 | | - try { |
140 | | - if (!Files.isFileNameValid(filename)) { |
141 | | - // Files.isFileNameValid(filename) throws an exception itself |
142 | | - } else if (self.fileList.inList(filename)) { |
143 | | - throw t('files', '{newName} already exists', {newName: filename}, undefined, { |
144 | | - escape: false |
145 | | - }); |
146 | | - } else { |
147 | | - return true; |
148 | | - } |
149 | | - } catch (error) { |
150 | | - $input.attr('title', error); |
151 | | - $input.addClass('error'); |
152 | | - } |
153 | | - return false; |
154 | | - }; |
155 | | - |
156 | | - // verify filename on typing |
157 | | - $input.keyup(function() { |
158 | | - if (checkInput()) { |
159 | | - $input.removeClass('error'); |
160 | | - } |
161 | | - }); |
162 | | - |
163 | | - $submit.click(function(event) { |
164 | | - event.stopPropagation(); |
165 | | - event.preventDefault(); |
166 | | - $form.submit(); |
167 | | - }); |
168 | | - |
169 | | - $input.focus(); |
170 | | - // pre select name up to the extension |
171 | | - lastPos = newName.lastIndexOf('.'); |
172 | | - if (lastPos === -1) { |
173 | | - lastPos = newName.length; |
174 | | - } |
175 | | - $input.selectRange(0, lastPos); |
176 | | - |
177 | | - $form.submit(function(event) { |
178 | | - event.stopPropagation(); |
179 | | - event.preventDefault(); |
180 | | - |
181 | | - if (checkInput()) { |
182 | | - var newname = $input.val().trim(); |
183 | | - |
184 | | - /* Find the right actionHandler that should be called. |
185 | | - * Actions is retrieved by using `actionSpec.id` */ |
186 | | - var action = _.filter(self._menuItems, function(item) { |
187 | | - return item.id == $target.attr('data-action'); |
188 | | - }).pop(); |
189 | | - action.actionHandler(newname); |
190 | | - |
191 | | - $form.remove(); |
192 | | - $target.find('.displayname').removeClass('hidden'); |
193 | | - OC.hideMenus(); |
194 | | - } |
195 | | - }); |
| 106 | + var newname = $target.attr('data-templatename'); |
| 107 | + var action = _.filter(self._menuItems, function(item) { |
| 108 | + return item.id == $target.attr('data-action'); |
| 109 | + }).pop(); |
| 110 | + action.actionHandler(newname); |
| 111 | + OC.hideMenus(); |
196 | 112 | }, |
197 | 113 |
|
198 | 114 | /** |
|
0 commit comments