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
533bb6a8
Commit
533bb6a8
authored
Dec 21, 2015
by
Fabian-Andree Heidemann
Browse files
[file] fix issue with non existent openPath via prompt to set new one
parent
6f9fe1b5
Changes
1
Hide whitespace changes
Inline
Side-by-side
vispa/extensions/file/static/js/views.js
View file @
533bb6a8
define
([
"
vispa/views/center
"
,
"
vispa/views/dialog
"
,
"
./menuentries
"
,
"
./browser/browser
"
,
"
./selector/selector
"
,
"
text!../html/fileselectorBottom.html
"
,
],
function
(
CenterView
,
DialogView
,
MenuEntries
,
FileBrowser
,
FileSelector
,
BottomTmpl
)
{
"
vispa/views/center
"
,
"
vispa/views/dialog
"
,
"
./menuentries
"
,
"
./browser/browser
"
,
"
./selector/selector
"
,
"
text!../html/fileselectorBottom.html
"
,
],
function
(
CenterView
,
DialogView
,
MenuEntries
,
FileBrowser
,
FileSelector
,
BottomTmpl
)
{
var
FileBrowserView
=
CenterView
.
_extend
({
init
:
function
init
(
args
)
{
init
.
_super
.
apply
(
this
,
arguments
);
var
self
=
this
;
// Store the FileBrowser so that it is known in the View.
// This is needed for using "fb" methods inside the callback functions
// in the keyboard shortcuts.
this
.
fb
=
new
FileBrowser
(
this
);
// Add the menu items
for
(
var
i
in
MenuEntries
)
{
for
(
var
i
in
MenuEntries
)
{
this
.
addMenuEntry
(
i
,
MenuEntries
[
i
]);
}
// set default state and if args.path is null remove it
if
(
args
!==
undefined
)
if
(
args
.
path
===
null
)
delete
args
.
path
;
if
(
args
!==
undefined
)
if
(
args
.
path
===
null
)
delete
args
.
path
;
this
.
setupState
({
path
:
this
.
getPreference
(
"
OpenPath
"
)
},
args
);
// set path to default if not set
this
.
setLabel
(
this
.
getState
(
'
path
'
),
true
);
// register watch event
this
.
onSocket
(
"
watch
"
,
function
(
data
)
{
this
.
onSocket
(
"
watch
"
,
function
(
data
)
{
if
(
data
.
event
!=
"
change
"
)
{
return
;
}
...
...
@@ -45,28 +46,47 @@ define([
self
.
fb
.
updateView
();
}
});
if
(
!
args
.
path
)
{
self
.
GET
(
"
/ajax/fs/exists
"
,
{
path
:
self
.
getPreference
(
"
OpenPath
"
)
},
function
(
err
,
res
)
{
if
(
!
err
&&
res
!=
"
d
"
)
{
self
.
getWorkspace
().
prompt
(
"
The open path
\"
"
+
self
.
getPreference
(
"
OpenPath
"
)
+
"
\"
does not exist. Please set a
"
+
"
new one.
"
,
function
(
newpath
)
{
self
.
setPreference
(
"
OpenPath
"
,
newpath
)
self
.
spawnInstance
(
"
file
"
,
"
FileBrowser
"
,
args
);
self
.
close
();
},
{
defaultValue
:
self
.
getPreference
(
"
OpenPath
"
),
placeholder
:
"
new open path
"
}
);
}
});
}
},
getFragment
:
function
()
{
getFragment
:
function
()
{
return
this
.
getState
(
"
path
"
);
},
applyFragment
:
function
(
fragment
)
{
applyFragment
:
function
(
fragment
)
{
this
.
setState
(
"
path
"
,
fragment
);
return
this
;
},
// applyPreferences is called when there was a change to the preferences
applyPreferences
:
function
applyPreferences
()
{
applyPreferences
.
_super
.
call
(
this
);
this
.
fb
.
refresh
(
this
.
fb
.
workflow
.
data
);
this
.
fb
.
view
.
toggleViewMenu
();
this
.
fb
.
sorting
.
toggleSortButtons
();
},
render
:
function
(
node
)
{
render
:
function
(
node
)
{
var
self
=
this
;
this
.
setIcon
(
"
fi fi-folder
"
);
...
...
@@ -79,12 +99,12 @@ define([
$
(
"
.tableButton
"
,
this
.
_nodes
.
fastMenu
).
addClass
(
"
disabled
"
);
$
(
"
.symbolButton
"
,
this
.
_nodes
.
fastMenu
).
removeClass
(
"
disabled
"
);
}
node
.
addClass
(
"
filebrowser
"
);
this
.
fb
.
setContent
(
node
);
self
.
logger
.
info
(
"
initially filled the content node
"
);
this
.
setLoading
(
false
);
},
...
...
@@ -100,38 +120,39 @@ define([
this
.
fb
.
events
.
disableDragAndDropUpload
();
},
onClose
:
function
()
{
onClose
:
function
()
{
this
.
removeSocketListener
(
"
watch
"
);
this
.
POST
(
"
/ajax/fs/unwatch
"
,
{
watch_id
:
"
0
"
});
return
this
;
},
});
var
FileSelectorView
=
DialogView
.
_extend
({
init
:
function
init
(
args
)
{
init
.
_super
.
apply
(
this
,
arguments
);
var
self
=
this
;
// Add the menu items
for
(
var
i
in
MenuEntries
)
{
for
(
var
i
in
MenuEntries
)
{
this
.
addMenuEntry
(
i
,
MenuEntries
[
i
]);
}
// set default state and if args.path is null remove it
if
(
args
!==
undefined
)
if
(
args
.
path
===
null
)
delete
args
.
path
;
if
(
args
!==
undefined
)
if
(
args
.
path
===
null
)
delete
args
.
path
;
this
.
setupState
({
path
:
this
.
getPreference
(
"
OpenPath
"
)
},
args
);
this
.
multimode
=
args
.
multimode
===
undefined
?
false
:
args
.
multimode
;
this
.
foldermode
=
args
.
foldermode
===
undefined
?
false
:
args
.
foldermode
;
this
.
cb_args
=
args
.
cb_args
||
{};
// Define a default callback if no callback is defined
var
defCallback
=
function
(
path
,
obj
)
{
var
defCallback
=
function
(
path
,
obj
)
{
console
.
log
(
path
);
console
.
log
(
obj
);
};
...
...
@@ -141,92 +162,111 @@ define([
this
.
fb
=
new
FileSelector
(
this
,
args
);
this
.
setLabel
(
"
id:
"
+
this
.
getId
());
// register watch event
this
.
onSocket
(
"
watch
"
,
function
(
data
)
{
this
.
onSocket
(
"
watch
"
,
function
(
data
)
{
if
(
data
.
event
!=
"
change
"
)
return
;
self
.
fb
.
updateView
(
100
);
});
if
(
!
args
.
path
)
{
self
.
GET
(
"
/ajax/fs/exists
"
,
{
path
:
self
.
getPreference
(
"
OpenPath
"
)
},
function
(
err
,
res
)
{
if
(
!
err
&&
res
!=
"
d
"
)
{
self
.
getWorkspace
().
prompt
(
"
The open path
\"
"
+
self
.
getPreference
(
"
OpenPath
"
)
+
"
\"
does not exist. Please set a
"
+
"
new one.
"
,
function
(
newpath
)
{
self
.
setPreference
(
"
OpenPath
"
,
newpath
)
self
.
spawnInstance
(
"
file
"
,
"
FileSelector
"
,
args
);
self
.
close
();
},
{
defaultValue
:
self
.
getPreference
(
"
OpenPath
"
),
placeholder
:
"
new open path
"
}
);
}
});
}
},
render
:
function
(
content
,
footer
)
{
render
:
function
(
content
,
footer
)
{
var
self
=
this
;
this
.
selectButton
=
null
;
this
.
inputField
=
null
;
this
.
setLoading
(
true
);
// TODO
// This is a hack!!!
content
.
addClass
(
"
fileselector
"
);
content
.
parent
().
css
(
"
overflow-y
"
,
"
hidden
"
);
this
.
fb
.
setContent
(
content
);
footer
.
append
(
$
(
BottomTmpl
));
self
.
selectButton
=
$
(
"
.fs-select
"
,
footer
);
if
(
!
self
.
foldermode
)
{
self
.
selectButton
.
addClass
(
"
disabled
"
);
}
self
.
inputField
=
$
(
"
#FileSelectorFileInput
"
,
footer
);
if
(
self
.
multimode
)
{
self
.
inputField
.
css
(
"
visibility
"
,
"
hidden
"
);
footer
.
append
(
$
(
BottomTmpl
));
self
.
selectButton
=
$
(
"
.fs-select
"
,
footer
);
if
(
!
self
.
foldermode
)
{
self
.
selectButton
.
addClass
(
"
disabled
"
);
}
self
.
inputField
=
$
(
"
#FileSelectorFileInput
"
,
footer
);
if
(
self
.
multimode
)
{
self
.
inputField
.
css
(
"
visibility
"
,
"
hidden
"
);
}
self
.
selectButton
.
on
(
"
click
"
,
function
(
event
)
{
event
.
preventDefault
();
if
(
Object
.
keys
(
self
.
fb
.
selections
.
entries
).
length
===
0
&&
!
self
.
foldermode
&&
self
.
inputField
.
val
()
===
""
)
{
vispa
.
messenger
.
info
(
"
nothing selected
"
);
self
.
close
();
}
else
if
(
Object
.
keys
(
self
.
fb
.
selections
.
entries
).
length
===
0
&&
!
self
.
foldermode
)
{
self
.
fb
.
actions
.
select
(
self
.
inputField
.
val
());
}
else
{
self
.
fb
.
actions
.
select
();
}
self
.
selectButton
.
on
(
"
click
"
,
function
(
event
)
{
});
var
closeBotton
=
$
(
"
.fs-close
"
,
footer
);
closeBotton
.
on
(
"
click
"
,
function
(
event
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
self
.
close
();
});
self
.
inputField
.
keypress
(
function
(
event
)
{
var
charCode
=
(
typeof
event
.
which
==
"
undefined
"
)
?
event
.
keyCode
:
event
.
which
;
// Enter == 13
if
(
charCode
==
13
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
if
(
Object
.
keys
(
self
.
fb
.
selections
.
entries
).
length
===
0
&&
!
self
.
foldermode
&&
self
.
inputField
.
val
()
===
""
)
{
vispa
.
messenger
.
info
(
"
nothing selected
"
);
self
.
close
();
}
else
if
(
Object
.
keys
(
self
.
fb
.
sele
ctions
.
entries
).
length
===
0
&&
!
self
.
foldermode
)
{
self
.
fb
.
actions
.
select
(
self
.
inputField
.
val
());
}
else
{
self
.
fb
.
actions
.
select
();
var
nSelectedEntries
=
Object
.
keys
(
self
.
fb
.
selections
.
entries
).
length
;
var
inputString
=
self
.
inputField
.
val
()
;
if
(
inputString
!==
""
)
{
if
(
nSelectedEntries
<
2
)
{
self
.
fb
.
a
ctions
.
select
(
self
.
inputField
.
val
());
}
else
{
alert
(
"
Multiple selections can not be combined with the input field.
"
);
}
}
});
var
closeBotton
=
$
(
"
.fs-close
"
,
footer
);
closeBotton
.
on
(
"
click
"
,
function
(
event
)
{
}
// Escape == 27
if
(
charCode
==
27
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
self
.
close
();
});
self
.
inputField
.
keypress
(
function
(
event
)
{
var
charCode
=
(
typeof
event
.
which
==
"
undefined
"
)
?
event
.
keyCode
:
event
.
which
;
// Enter == 13
if
(
charCode
==
13
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
var
nSelectedEntries
=
Object
.
keys
(
self
.
fb
.
selections
.
entries
).
length
;
var
inputString
=
self
.
inputField
.
val
();
if
(
inputString
!==
""
)
{
if
(
nSelectedEntries
<
2
)
{
self
.
fb
.
actions
.
select
(
self
.
inputField
.
val
());
}
else
{
alert
(
"
Multiple selections can not be combined with the input field.
"
);
}
}
}
// Escape == 27
if
(
charCode
==
27
)
{
event
.
stopPropagation
();
event
.
preventDefault
();
self
.
close
();
}
});
self
.
inputField
.
keyup
(
function
()
{
self
.
fb
.
selections
.
toggleSelectionButton
();
});
}
});
self
.
inputField
.
keyup
(
function
()
{
self
.
fb
.
selections
.
toggleSelectionButton
();
});
self
.
applyPreferences
();
// hide the loader overlay
self
.
setLoading
(
false
);
},
...
...
@@ -240,7 +280,7 @@ define([
onBlur
:
function
()
{
this
.
fb
.
events
.
disableDragAndDropUpload
();
},
onClose
:
function
()
{
onClose
:
function
()
{
if
(
!
this
.
fb
.
workflow
.
callbackFired
)
this
.
callback
(
null
,
this
.
cb_args
);
this
.
removeSocketListener
(
"
watch
"
);
this
.
POST
(
"
/ajax/fs/unwatch
"
,
{
...
...
@@ -249,9 +289,9 @@ define([
return
this
;
}
});
return
{
Browser
:
FileBrowserView
,
Selector
:
FileSelectorView
,
};
});
});
\ No newline at end of file
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