Got stuff working!
This commit is contained in:
parent
000469e16f
commit
11579fc604
@ -42,12 +42,12 @@ class MediaController(BaseController):
|
||||
|
||||
def __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=[]):
|
||||
old_root = parent
|
||||
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):
|
||||
if root != old_root:
|
||||
break
|
||||
@ -75,6 +75,13 @@ class MediaController(BaseController):
|
||||
#return pformat(c.directories, indent=2)
|
||||
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
|
||||
def create_directory(self):
|
||||
"""
|
||||
|
@ -18,17 +18,37 @@
|
||||
*****************************************************************************/
|
||||
|
||||
ScribeEngine.Namespace.create("ScribeEngine.Media", {
|
||||
new_directory: function ()
|
||||
newDirectory: function ()
|
||||
{
|
||||
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.click("#new-directory", ScribeEngine.Media.new_directory);
|
||||
ScribeEngine.Events.click("#new-directory", ScribeEngine.Media.newDirectory);
|
||||
ScribeEngine.Events.click("#file-select", window.close);
|
||||
});
|
||||
|
@ -133,7 +133,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
|
||||
},
|
||||
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!
|
||||
if (cmsURL.indexOf("?") < 0)
|
||||
{
|
||||
@ -180,7 +180,7 @@ ScribeEngine.Namespace.create("ScribeEngine.Widgets", {
|
||||
tree: function (selector, tree_data, onselect)
|
||||
{
|
||||
$(selector)
|
||||
.bind("set_focus.jstree", onselect)
|
||||
.bind("click.jstree", onselect)
|
||||
.jstree({
|
||||
plugins: ["themes", "json_data"],
|
||||
json_data: {data: tree_data},
|
||||
|
@ -43,7 +43,7 @@
|
||||
<input type="button" id="file-select" value="Select"/>
|
||||
</div>
|
||||
<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>
|
||||
</body>
|
||||
</html>
|
||||
|
Reference in New Issue
Block a user