Got stuff working!
This commit is contained in:
parent
000469e16f
commit
11579fc604
@ -42,12 +42,12 @@ class MediaController(BaseController):
|
|||||||
|
|
||||||
def __before__(self):
|
def __before__(self):
|
||||||
BaseController.__before__(self)
|
BaseController.__before__(self)
|
||||||
self._add_javascript('ScribeEngine.Media.js')
|
self._add_javascript(u'ScribeEngine.Media.js')
|
||||||
|
|
||||||
def _get_directories(self, parent=None, tree=[]):
|
def _get_directories(self, parent=None, tree=[]):
|
||||||
old_root = parent
|
old_root = parent
|
||||||
dirname = os.path.split(parent)[1]
|
dirname = os.path.split(parent)[1]
|
||||||
node = {'data': dirname, u'state': u'open'}
|
node = {u'data': dirname, u'state': u'open'}
|
||||||
for root, dirs, files in os.walk(parent):
|
for root, dirs, files in os.walk(parent):
|
||||||
if root != old_root:
|
if root != old_root:
|
||||||
break
|
break
|
||||||
@ -75,6 +75,13 @@ class MediaController(BaseController):
|
|||||||
#return pformat(c.directories, indent=2)
|
#return pformat(c.directories, indent=2)
|
||||||
return render(u'/media/index.mako')
|
return render(u'/media/index.mako')
|
||||||
|
|
||||||
|
@jsonify
|
||||||
|
def get_files(self):
|
||||||
|
path = request.GET.get(u'path', u'').split(u',')
|
||||||
|
dirpath = os.path.join(config[u'paths.media'], *path)
|
||||||
|
#log.debug(dirpath)
|
||||||
|
return self._get_files(dirpath)
|
||||||
|
|
||||||
@jsonify
|
@jsonify
|
||||||
def create_directory(self):
|
def create_directory(self):
|
||||||
"""
|
"""
|
||||||
|
@ -18,17 +18,37 @@
|
|||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
ScribeEngine.Namespace.create("ScribeEngine.Media", {
|
ScribeEngine.Namespace.create("ScribeEngine.Media", {
|
||||||
new_directory: function ()
|
newDirectory: function ()
|
||||||
{
|
{
|
||||||
var dirname = prompt("New Directory:", "directory");
|
var dirname = prompt("New Directory:", "directory");
|
||||||
},
|
},
|
||||||
get_files: function (event, data)
|
getFiles: function (event)
|
||||||
{
|
{
|
||||||
alert(data.inst.get_path(ScribeEngine.Events.getElement(event)));
|
var tree = jQuery.jstree._focused();
|
||||||
|
var path = tree.get_path(ScribeEngine.Events.getElement(event));
|
||||||
|
$.getJSON(
|
||||||
|
'/media/get-files',
|
||||||
|
{"path": path.toString()},
|
||||||
|
function (data, textStatus) {
|
||||||
|
$("#file-list > ul").html("");
|
||||||
|
$.each(data, function () {
|
||||||
|
var filename = this;
|
||||||
|
if (filename.length > 15)
|
||||||
|
{
|
||||||
|
filename = filename.substr(0, 12) + "...";
|
||||||
|
}
|
||||||
|
$("#file-list > ul").append(
|
||||||
|
$("<li>")
|
||||||
|
.append($("<div>").attr("class", "file").html(" "))
|
||||||
|
.append($("<div>").attr("class", "caption").attr("title", filename).text(filename))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
ScribeEngine.Events.load(function () {
|
ScribeEngine.Events.load(function () {
|
||||||
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.new_directory);
|
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory);
|
||||||
ScribeEngine.Events.click("#file-select", window.close);
|
ScribeEngine.Events.click("#file-select", window.close);
|
||||||
});
|
});
|
||||||
|
@ -133,7 +133,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
|
|||||||
},
|
},
|
||||||
fileBrowser: function (field_name, url, type, win)
|
fileBrowser: function (field_name, url, type, win)
|
||||||
{
|
{
|
||||||
alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
|
//alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
|
||||||
var cmsURL = window.location.toString(); // script URL - use an absolute path!
|
var cmsURL = window.location.toString(); // script URL - use an absolute path!
|
||||||
if (cmsURL.indexOf("?") < 0)
|
if (cmsURL.indexOf("?") < 0)
|
||||||
{
|
{
|
||||||
@ -180,7 +180,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
|
|||||||
tree: function (selector, tree_data, onselect)
|
tree: function (selector, tree_data, onselect)
|
||||||
{
|
{
|
||||||
$(selector)
|
$(selector)
|
||||||
.bind("set_focus.jstree", onselect)
|
.bind("click.jstree", onselect)
|
||||||
.jstree({
|
.jstree({
|
||||||
plugins: ["themes", "json_data"],
|
plugins: ["themes", "json_data"],
|
||||||
json_data: {data: tree_data},
|
json_data: {data: tree_data},
|
||||||
|
@ -43,7 +43,7 @@
|
|||||||
<input type="button" id="file-select" value="Select"/>
|
<input type="button" id="file-select" value="Select"/>
|
||||||
</div>
|
</div>
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
ScribeEngine.Widgets.tree("#directory-tree", ${c.directories | n}, ScribeEngine.Media.get_files);
|
ScribeEngine.Widgets.tree("#directory-tree", ${c.directories | n}, ScribeEngine.Media.getFiles);
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Reference in New Issue
Block a user