Make it possible to rename documents by clicking on title
This commit is contained in:
parent
f4425835af
commit
d56ef4f0b6
@ -22,6 +22,24 @@ class SessionController extends Controller{
|
||||
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){
|
||||
$uid = self::preDispatch();
|
||||
$fileId = intval(@$args['file_id']);
|
||||
|
@ -73,6 +73,10 @@ $this->create('documents_session_joinasguest', 'ajax/session/joinasguest/{token}
|
||||
->post()
|
||||
->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')
|
||||
->post()
|
||||
|
@ -280,4 +280,9 @@ margin-top:-1px;
|
||||
.dojoTabular {border-collapse: collapse; border-spacing: 0; border: 1px solid #ccc; margin: 0 1.5em;}
|
||||
.dojoTabular th {text-align: center; font-weight: bold;}
|
||||
.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,
|
||||
esId : false,
|
||||
ready :false,
|
||||
fileName: null,
|
||||
|
||||
UI : {
|
||||
/* Overlay HTML */
|
||||
@ -186,8 +187,10 @@ var documentsMain = {
|
||||
// fade out file list and show WebODF canvas
|
||||
$('#content').fadeOut('fast').promise().done(function() {
|
||||
|
||||
documentsMain.fileId = response.file_id;
|
||||
documentsMain.fileName = documentsMain.getNameByFileid(response.file_id);
|
||||
documentsMain.UI.showEditor(
|
||||
documentsMain.getNameByFileid(response.file_id),
|
||||
documentsMain.fileName,
|
||||
response.permissions & OC.PERMISSION_SHARE && !documentsMain.isGuest
|
||||
);
|
||||
var serverFactory = new ServerFactory();
|
||||
@ -281,7 +284,42 @@ var documentsMain = {
|
||||
});
|
||||
$.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);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
onRenamePrompt: function() {
|
||||
var name = documentsMain.fileName;
|
||||
var lastPos = name.lastIndexOf('.');
|
||||
var extension = name.substr(lastPos + 1);
|
||||
name = name.substr(0, lastPos);
|
||||
// FIXME: don't use an ugly prompt but an inline field
|
||||
// FIXME: check for invalid characters
|
||||
var newName = prompt(t('document', 'Please enter the document name'), name);
|
||||
if (newName !== null && newName !== '') {
|
||||
documentsMain.renameDocument(newName + '.' + extension);
|
||||
}
|
||||
},
|
||||
|
||||
onClose: function() {
|
||||
"use strict";
|
||||
|
||||
@ -433,6 +471,7 @@ $(document).ready(function() {
|
||||
}
|
||||
});
|
||||
|
||||
$(document.body).on('click', '#document-title', documentsMain.onRenamePrompt);
|
||||
$(document.body).on('click', '#odf-close', documentsMain.onClose);
|
||||
$(document.body).on('click', '#odf-invite', documentsMain.onInvite);
|
||||
$(document.body).on('click', '#odf-join', function(event){
|
||||
|
11
lib/file.php
11
lib/file.php
@ -151,6 +151,17 @@ class File {
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user