Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
3pia
VISPA
VISPA web
Commits
56aae606
Commit
56aae606
authored
Nov 02, 2014
by
ThorbenQuast
Browse files
editor: read-only mode, fix #1969
parent
4d9f7723
Changes
3
Hide whitespace changes
Inline
Side-by-side
vispa/extensions/codeeditor/static/js/editor.js
View file @
56aae606
...
...
@@ -20,6 +20,7 @@ var CodeEditor = Emitter.extend({
this
.
node
=
null
;
this
.
autosaveTimeOut
=
null
;
this
.
writable
=
true
;
//default case = new file case
},
setup
:
function
(
node
)
{
...
...
@@ -114,10 +115,11 @@ var CodeEditor = Emitter.extend({
self
.
view
.
close
();
}
self
.
path
=
path
;
self
.
setContent
(
res
.
content
)
;
self
.
writable
=
res
.
writable
;
self
.
mtime
=
res
.
mtime
;
self
.
setContent
(
res
.
content
);
self
.
lastContent
=
self
.
getContent
();
self
.
setMode
(
path
);
self
.
setMode
();
self
.
goToTop
();
self
.
checkModifications
();
self
.
setupAutoSave
();
...
...
@@ -173,7 +175,7 @@ var CodeEditor = Emitter.extend({
if
(
isModified
!=
this
.
view
.
isModified
())
{
this
.
view
.
setModified
(
isModified
);
}
this
.
view
.
toggleMenuEntry
(
"
save
"
,
isModified
&&
this
.
path
);
this
.
view
.
toggleMenuEntry
(
"
save
"
,
isModified
&&
this
.
path
&&
this
.
writable
);
return
this
;
},
...
...
@@ -230,20 +232,12 @@ var CodeEditor = Emitter.extend({
var
msg
=
"
<html>File extension '
"
+
fileExtension
+
"
' is not supported! <br /> Save anyway?</html>
"
;
self
.
view
.
confirm
(
msg
,
function
(
confirmed
)
{
if
(
confirmed
)
{
self
.
path
=
path
;
self
.
view
.
preview
.
setPath
(
path
,
true
);
self
.
save
(
null
,
"
new
"
);
if
(
$
.
isFunction
(
callback
))
callback
();
self
.
save
(
callback
,
"
new
"
,
path
);
}
});
}
else
{
self
.
path
=
path
;
self
.
view
.
preview
.
setPath
(
path
,
true
);
self
.
view
.
output
.
setCommandLine
();
self
.
save
(
null
,
"
new
"
);
if
(
$
.
isFunction
(
callback
))
callback
();
self
.
save
(
callback
,
"
new
"
,
path
);
}
},
sort
:
[
"
name
"
,
"
ext
"
],
...
...
@@ -254,7 +248,7 @@ var CodeEditor = Emitter.extend({
return
this
;
},
save
:
function
(
callback
,
option
)
{
save
:
function
(
callback
,
option
,
path
)
{
var
self
=
this
;
this
.
setupAutoSave
();
...
...
@@ -264,7 +258,14 @@ var CodeEditor = Emitter.extend({
return
this
;
}
if
(
!
this
.
path
)
{
if
(
!
this
.
writable
&&
option
!=
"
new
"
)
{
console
.
log
(
"
No writing access!
"
);
if
(
$
.
isFunction
(
callback
))
callback
();
return
this
;
}
if
(
!
this
.
path
&&
!
path
)
{
this
.
saveAs
(
callback
);
return
this
;
}
...
...
@@ -273,17 +274,24 @@ var CodeEditor = Emitter.extend({
this
.
saving_processing
=
true
;
this
.
view
.
POST
(
vispa
.
url
.
dynamic
(
"
/ajax/fs/save_file
"
),
{
path
:
this
.
path
,
path
:
path
?
path
:
this
.
path
,
content
:
this
.
getContent
(),
utf8
:
true
,
watch_id
:
"
code
"
}).
done
(
function
(
res
)
{
self
.
mtime
=
res
.
mtime
;
self
.
lastContent
=
self
.
getContent
();
self
.
checkModifications
();
self
.
setMode
();
if
(
$
.
isFunction
(
callback
))
callback
();
if
(
!
res
.
success
)
{
self
.
view
.
alert
(
"
Saving not possible. Please check file permissions.
"
);
}
else
{
self
.
mtime
=
res
.
mtime
;
self
.
path
=
res
.
path
;
self
.
writable
=
true
;
self
.
lastContent
=
self
.
getContent
();
self
.
checkModifications
();
self
.
setMode
();
self
.
view
.
preview
.
setPath
(
self
.
path
,
true
);
if
(
$
.
isFunction
(
callback
))
callback
();
}
}).
always
(
function
()
{
self
.
view
.
setLoading
(
false
);
self
.
saving_processing
=
false
;
...
...
@@ -312,7 +320,12 @@ var CodeEditor = Emitter.extend({
if
(
path
==
null
)
return
this
;
this
.
view
.
setLabel
(
path
,
true
);
var
label
=
path
;
if
(
!
this
.
writable
)
label
=
label
+
"
Read-Only
"
;
this
.
view
.
setLabel
(
label
,
true
);
var
fileExtension
=
path
.
split
(
"
.
"
).
pop
().
toLowerCase
();
if
(
!~
this
.
view
.
_extension
.
fileExtensions
.
indexOf
(
fileExtension
))
{
...
...
@@ -436,5 +449,5 @@ var CodeEditor = Emitter.extend({
}
return
mode
;
}
});
\ No newline at end of file
vispa/extensions/codeeditor/static/js/extension.js
View file @
56aae606
...
...
@@ -185,13 +185,17 @@ var CodeEditorView = vispa.ExtensionView.Center.extend({
var
doAsk
=
!
this
.
forceClose
&&
this
.
isModified
();
if
(
doAsk
)
this
.
confirm
(
"
Save changes before closing?
"
,
function
(
b
)
{
self
.
forceClose
=
true
;
if
(
b
)
self
.
editor
.
save
(
function
()
{
cleanUp
();
self
.
close
();
//close the editor after saving
});
else
var
after_save
=
function
()
{
self
.
forceClose
=
true
;
cleanUp
();
self
.
close
();
//close the editor after saving
}
if
(
b
)
{
if
(
self
.
editor
.
writable
)
self
.
editor
.
save
(
after_save
);
else
self
.
editor
.
saveAs
(
after_save
);
}
else
self
.
close
();
});
else
...
...
vispa/remote/filesystem.py
View file @
56aae606
...
...
@@ -385,8 +385,9 @@ class FileSystem(object):
return
json
.
dumps
({
"mtime"
:
os
.
path
.
getmtime
(
path
),
"success"
:
mtime
>
0
,
"watch_error"
:
watch_error
"success"
:
mtime
>
0
and
self
.
checkPermissions
(
path
),
#save is not successful, if file not writable
"watch_error"
:
watch_error
,
"path"
:
path
})
def
get_file
(
self
,
path
,
binary
=
False
,
...
...
@@ -404,18 +405,26 @@ class FileSystem(object):
content
=
f
.
read
()
if
utf8
:
content
=
content
.
decode
(
'utf8'
)
#new: check for writing rights
writable
=
self
.
checkPermissions
(
path
)
mtime
=
os
.
path
.
getmtime
(
path
)
except
Exception
as
e
:
mtime
=
0
content
=
""
writable
=
None
return
json
.
dumps
({
"content"
:
content
,
"mtime"
:
mtime
,
"success"
:
mtime
>
0
,
"watch_error"
:
watch_error
"watch_error"
:
watch_error
,
"writable"
:
writable
})
def
checkPermissions
(
self
,
path
):
return
os
.
access
(
path
,
os
.
W_OK
)
def
save_file_content
(
self
,
filename
,
content
,
path
=
None
,
force
=
True
,
append
=
False
):
# check write permissions
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment