public
Last active

  • Download Gist
controller/browse.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
McAdmin.browseController = SC.TreeController.create(
/** @scope McAdmin.browseController.prototype */ {
 
allowsMultipleSelection: NO,
content: null,
count: 0,
countBinding: "*arrangedObjects.length",
displayItem: function() {
var list = McAdmin.browsePage.getPath('treeView.contentView'),
selectedItem = list.selection.firstObject(),
itemView = SC.LabelView.design({
escapeHTML: NO,
classNames: 'instructions-tab',
value: "<p>This is a test of the dynamic view broadcast system. This is only a test.</p>"
});
McAdmin.viewRawItemController.set('nowShowing', McAdmin.mainPage.getPath('instructions'));
}
});
data_sources/item.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
// ==========================================================================
// Project: MetaCollection Admin
// MetaCollection Admin is a web-based tool for managing a MetaCollection installation.
//
// This project is hosted at Google Code at http://code.google.com/p/metacollection-admin/
//
// This project is licensed under the BSD license. See the License.txt file for more information.
// ==========================================================================
/*globals McAdmin */
 
sc_require('models/item');
McAdmin.ROOT_ITEM_QUERY = SC.Query.local(McAdmin.Item);
 
/** @class
 
(Document Your Data Source Here)
 
@extends SC.DataSource
*/
McAdmin.ItemDataSource = SC.DataSource.extend(
/** @scope McAdmin.ItemDataSource.prototype */ {
 
// ..........................................................
// QUERY SUPPORT
//
 
fetch: function(store, query) {
var propfindRequestData = '<?xml version="1.0"?><D:propfind xmlns:D="DAV:" xmlns:mc="uri://MetaCollection/v2"><D:prop><D:displayname/><mc:mimetype/><mc:resourceprovider/><mc:version/><mc:published/><mc:name/><mc:id/></D:prop></D:propfind>';
// TODO: Add handlers to fetch data for specific queries.
// call store.dataSourceDidFetchQuery(query) when done.
 
if (query === McAdmin.ROOT_ITEM_QUERY) {
// TODO: When loading an item tree we should use a remote query and skip/take items
var req = SC.Request.create()
.set('address', McAdmin.COLLECTION_URL)
.set('type', 'PROPFIND').set('body', propfindRequestData)
.xml()
.notify(this, 'didFetchItems', store, query)
req.isAsynchronous = NO,
req.send();
 
return YES;
} else if (query.partial) {
var req = SC.Request.create()
.set('address', query.href ? McAdmin.COLLECTION_URL + query.href : McAdmin.COLLECTION_URL)
.set('type', 'PROPFIND').set('body', propfindRequestData)
.xml()
.notify(this, 'didFetchItems', store, query)
req.isAsynchronous = NO,
req.send();
 
return YES;
}
return NO ; // return YES if you handled the query
},
didFetchItems: function(response, store, query) {
if (SC.ok(response)) {
store.loadRecords(McAdmin.Item, this.makeTreeItemList(response.get('body')));
store.dataSourceDidFetchQuery(query);
} else store.dataSourceDidErrorQuery(query, response);
},
makeTreeItemList: function(xmlResponses) {
var xmlRecords = xmlResponses.getElementsByTagName('D:response'),
records = [];
for(i = 0; i < xmlRecords.length; i++) {
var item = this.mungePropfind(xmlRecords[i])
records.push(this.rawItemToTreeItemChild(item));
}
return records;
},
rawItemToTreeItemChild: function(item) {
item.treeItemIsExpanded = NO;
item.title = item.name;
item.count = item.mimetype == "application/x-folder" ? 5 : 0;
if (item.mimetype == "application/x-folder") {
item.treeItemChildren = function(){
var ret = [],
inStore = McAdmin.store.find(McAdmin.Item, {guid: item.guid });
if (this.item.get('treeItemIsExpanded') && inStore.isError()) {
console.log("This href: " + this.item.get('href') + " - href:" + item.href);
var query = SC.Query.local(McAdmin.Item, {
href: this.item.get('href'),
partial: YES
}),
children = McAdmin.store.find(query);
item.count = children.length;
ret = children.slice(1, children.length);
}
return null;
}.property().cacheable()
}
return item;
},
mungePropfind: function(xmlRecord) {
var mungedItem = SC.Object.create({
href: xmlRecord.getElementsByTagName('D:href')[0].firstChild.nodeValue,
name: xmlRecord.getElementsByTagName('mc:name')[0].firstChild.nodeValue,
version: xmlRecord.getElementsByTagName('mc:version')[0].firstChild.nodeValue,
guid: xmlRecord.getElementsByTagName('mc:id')[0].firstChild.nodeValue,
mimetype: xmlRecord.getElementsByTagName('mc:mimetype')[0].firstChild.nodeValue
});
return mungedItem;
}
// snip a bunch of methods I'm not using
 
}) ;
main.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
McAdmin.main = function main() {
McAdmin.getPath('mainPage.mainPane').append();
 
var itemRecords = McAdmin.store.find(McAdmin.ROOT_ITEM_QUERY),
itemRecordsLength = itemRecords.length();
var rootItemNode = SC.Object.create({
treeItemIsExpanded: YES,
title: "Inventory",
treeItemChildren: itemRecords,
count: itemRecords.length(),
});
McAdmin.browseController.set('content', rootItemNode);
};
 
function main() { McAdmin.main(); }
model/item.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14
McAdmin.Item = SC.Record.extend(
/** @scope McAdmin.Item.prototype */ {
href: SC.Record.attr(String),
name: SC.Record.attr(String),
guid: SC.Record.attr(String),
mimetype: SC.Record.attr(String),
version: SC.Record.attr(Number),
properties: SC.Record.attr(Array),
relationships: SC.Record.attr(Array),
primaryKey: "href",
 
children: SC.Record.toMany('McAdmin.Item', {inverse: "parent", isMaster: YES }),
parent: SC.Record.toOne('McAdmin.Item', {inverse: "children", isMaster: NO })
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.