Merge pull request #159 from owncloud/renametitle
Make it possible to rename documents by clicking on title
This commit is contained in:
commit
10938317b5
@ -22,6 +22,24 @@ class SessionController extends Controller{
|
|||||||
self::join($uid, $file);
|
self::join($uid, $file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function renameDocument($args){
|
||||||
|
$fileId = intval(@$args['file_id']);
|
||||||
|
$name = @$_POST['name'];
|
||||||
|
$file = new File($fileId);
|
||||||
|
$l = new \OC_L10n('documents');
|
||||||
|
|
||||||
|
if (isset($name) && $file->getPermissions() & \OCP\PERMISSION_UPDATE) {
|
||||||
|
if ($file->renameTo($name)) {
|
||||||
|
// TODO: propagate to other clients
|
||||||
|
\OCP\JSON::success();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
\OCP\JSON::error(array(
|
||||||
|
'message' => $l->t('You don\'t have permission to rename this document')
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
public static function joinAsUser($args){
|
public static function joinAsUser($args){
|
||||||
$uid = self::preDispatch();
|
$uid = self::preDispatch();
|
||||||
$fileId = intval(@$args['file_id']);
|
$fileId = intval(@$args['file_id']);
|
||||||
|
@ -73,6 +73,10 @@ $this->create('documents_session_joinasguest', 'ajax/session/joinasguest/{token}
|
|||||||
->post()
|
->post()
|
||||||
->action('\OCA\Documents\SessionController', 'joinAsGuest')
|
->action('\OCA\Documents\SessionController', 'joinAsGuest')
|
||||||
;
|
;
|
||||||
|
$this->create('documents_session_renamedocument', 'ajax/session/renamedocument/{file_id}')
|
||||||
|
->post()
|
||||||
|
->action('\OCA\Documents\SessionController', 'renameDocument')
|
||||||
|
;
|
||||||
|
|
||||||
$this->create('documents_session_save', 'ajax/session/save')
|
$this->create('documents_session_save', 'ajax/session/save')
|
||||||
->post()
|
->post()
|
||||||
|
@ -124,6 +124,13 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
/*margin-left:-50%;*/
|
/*margin-left:-50%;*/
|
||||||
}
|
}
|
||||||
|
#document-title>input {
|
||||||
|
height:9px;
|
||||||
|
margin: 0;
|
||||||
|
padding-top:4px;
|
||||||
|
width: 300px;
|
||||||
|
}
|
||||||
|
|
||||||
#odf-close{
|
#odf-close{
|
||||||
float: right;
|
float: right;
|
||||||
}
|
}
|
||||||
@ -281,3 +288,8 @@ margin-top:-1px;
|
|||||||
.dojoTabular th {text-align: center; font-weight: bold;}
|
.dojoTabular th {text-align: center; font-weight: bold;}
|
||||||
.dojoTabular thead,.dojoTabular tfoot {background-color: #efefef; border: 1px solid #ccc; border-width: 1px 0;}
|
.dojoTabular thead,.dojoTabular tfoot {background-color: #efefef; border: 1px solid #ccc; border-width: 1px 0;}
|
||||||
.dojoTabular th,.dojoTabular td {padding: 0.25em 0.5em;}
|
.dojoTabular th,.dojoTabular td {padding: 0.25em 0.5em;}
|
||||||
|
|
||||||
|
/* raise notification z-index above the documents app */
|
||||||
|
#odf-toolbar + #notification-container {
|
||||||
|
z-index: 501;
|
||||||
|
}
|
||||||
|
@ -9,6 +9,7 @@ var documentsMain = {
|
|||||||
memberId : false,
|
memberId : false,
|
||||||
esId : false,
|
esId : false,
|
||||||
ready :false,
|
ready :false,
|
||||||
|
fileName: null,
|
||||||
|
|
||||||
UI : {
|
UI : {
|
||||||
/* Overlay HTML */
|
/* Overlay HTML */
|
||||||
@ -186,8 +187,10 @@ var documentsMain = {
|
|||||||
// fade out file list and show WebODF canvas
|
// fade out file list and show WebODF canvas
|
||||||
$('#content').fadeOut('fast').promise().done(function() {
|
$('#content').fadeOut('fast').promise().done(function() {
|
||||||
|
|
||||||
|
documentsMain.fileId = response.file_id;
|
||||||
|
documentsMain.fileName = documentsMain.getNameByFileid(response.file_id);
|
||||||
documentsMain.UI.showEditor(
|
documentsMain.UI.showEditor(
|
||||||
documentsMain.getNameByFileid(response.file_id),
|
documentsMain.fileName,
|
||||||
response.permissions & OC.PERMISSION_SHARE && !documentsMain.isGuest
|
response.permissions & OC.PERMISSION_SHARE && !documentsMain.isGuest
|
||||||
);
|
);
|
||||||
var serverFactory = new ServerFactory();
|
var serverFactory = new ServerFactory();
|
||||||
@ -282,6 +285,99 @@ var documentsMain = {
|
|||||||
$.post(OC.Router.generate('documents_user_invite'), {users: users});
|
$.post(OC.Router.generate('documents_user_invite'), {users: users});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
renameDocument: function(name) {
|
||||||
|
var url = OC.Router.generate('documents_session_renamedocument') + '/' + documentsMain.fileId;
|
||||||
|
$.post(
|
||||||
|
url,
|
||||||
|
{ name : name },
|
||||||
|
function(result) {
|
||||||
|
if (result && result.status === 'error') {
|
||||||
|
if (result.message){
|
||||||
|
OC.Notification.show(result.message);
|
||||||
|
setTimeout(function() {
|
||||||
|
OC.Notification.hide();
|
||||||
|
}, 10000);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
documentsMain.fileName = name;
|
||||||
|
$('title').text(documentsMain.UI.mainTitle + '| ' + name);
|
||||||
|
$('#document-title>div').text(name);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
// FIXME: copy/pasted from Files.isFileNameValid, needs refactor into core
|
||||||
|
isFileNameValid:function (name) {
|
||||||
|
if (name === '.') {
|
||||||
|
throw t('files', '\'.\' is an invalid file name.');
|
||||||
|
} else if (name.length === 0) {
|
||||||
|
throw t('files', 'File name cannot be empty.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for invalid characters
|
||||||
|
var invalid_characters = ['\\', '/', '<', '>', ':', '"', '|', '?', '*'];
|
||||||
|
for (var i = 0; i < invalid_characters.length; i++) {
|
||||||
|
if (name.indexOf(invalid_characters[i]) !== -1) {
|
||||||
|
throw t('files', "Invalid name, '\\', '/', '<', '>', ':', '\"', '|', '?' and '*' are not allowed.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
|
||||||
|
onRenamePrompt: function() {
|
||||||
|
var name = documentsMain.fileName;
|
||||||
|
var lastPos = name.lastIndexOf('.');
|
||||||
|
var extension = name.substr(lastPos + 1);
|
||||||
|
name = name.substr(0, lastPos);
|
||||||
|
var input = $('<input type="text" class="filename"/>').val(name);
|
||||||
|
$('#document-title').append(input);
|
||||||
|
$('#document-title>div').hide();
|
||||||
|
|
||||||
|
input.on('blur', function(){
|
||||||
|
var newName = input.val();
|
||||||
|
if (!newName || newName === name) {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.remove();
|
||||||
|
$('#document-title>div').show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newName = newName + '.' + extension;
|
||||||
|
try {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.removeClass('error');
|
||||||
|
if (documentsMain.isFileNameValid(newName)) {
|
||||||
|
input.tipsy('hide');
|
||||||
|
input.remove();
|
||||||
|
$('#document-title>div').show();
|
||||||
|
documentsMain.renameDocument(newName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
input.attr('title', error);
|
||||||
|
input.tipsy({gravity: 'n', trigger: 'manual'});
|
||||||
|
input.tipsy('show');
|
||||||
|
input.addClass('error');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.on('keyup', function(event){
|
||||||
|
if (event.keyCode === 27) {
|
||||||
|
// cancel by putting in an empty value
|
||||||
|
$(this).val('');
|
||||||
|
$(this).blur();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
if (event.keyCode === 13) {
|
||||||
|
$(this).blur();
|
||||||
|
event.preventDefault();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
input.focus();
|
||||||
|
input.selectRange(0, name.length);
|
||||||
|
},
|
||||||
|
|
||||||
onClose: function() {
|
onClose: function() {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
@ -433,6 +529,7 @@ $(document).ready(function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$(document.body).on('click', '#document-title>div', documentsMain.onRenamePrompt);
|
||||||
$(document.body).on('click', '#odf-close', documentsMain.onClose);
|
$(document.body).on('click', '#odf-close', documentsMain.onClose);
|
||||||
$(document.body).on('click', '#odf-invite', documentsMain.onInvite);
|
$(document.body).on('click', '#odf-invite', documentsMain.onInvite);
|
||||||
$(document.body).on('click', '#odf-join', function(event){
|
$(document.body).on('click', '#odf-join', function(event){
|
||||||
|
11
lib/file.php
11
lib/file.php
@ -151,6 +151,17 @@ class File {
|
|||||||
return $permissions;
|
return $permissions;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename this file to the given name
|
||||||
|
* @param string $newName name to give (without path)
|
||||||
|
* @return boolean true if rename succeeded, false otherwise
|
||||||
|
*/
|
||||||
|
public function renameTo($newName) {
|
||||||
|
list($owner, $path) = $this->getOwnerViewAndPath();
|
||||||
|
$newPath = dirname($path) . '/' . $newName;
|
||||||
|
return \OC\Files\Filesystem::rename($path, $newPath);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return string owner of the current file item
|
* @return string owner of the current file item
|
||||||
|
Loading…
x
Reference in New Issue
Block a user