You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.0 KiB
83 lines
3.0 KiB
(function () { |
|
var Store = BI.inherit(Fix.Model, { |
|
|
|
state: function () { |
|
return { |
|
entries: [], |
|
flattenEntry: [], |
|
masonry_selectedEntry: "" |
|
}; |
|
}, |
|
|
|
childContext: ["masonry_selectedEntry"], |
|
|
|
actions: { |
|
initEntryList: function (callback) { |
|
var self = this; |
|
Dec.Utils.getCompleteDirectoryTree(function (res) { |
|
self.model.entries = BI.Services.getService("dec.service.frame.entry").normalizeEntries(res.data); |
|
self.groupEntries(false); |
|
callback(); |
|
}); |
|
}, |
|
|
|
groupEntries: function () { |
|
var self = this; |
|
var tree = BI.Tree.transformToTreeFormat(this.model.entries); |
|
tree = tree[0]; |
|
BI.each(tree.children, function (index, item) { |
|
item.children = self._flattenEntry(item); |
|
}); |
|
this.model.flattenEntry = tree.children; |
|
}, |
|
|
|
formatItems: function () { |
|
var items = []; |
|
var columns = [0, 0]; |
|
var flattenEntry = this.model.flattenEntry.slice(0); |
|
flattenEntry = BI.filter(flattenEntry, function (index, entry) { |
|
return BI.isNotEmptyArray(entry.children); |
|
}); |
|
var entry = {}; |
|
while (flattenEntry.length > 0) { |
|
entry = flattenEntry.shift(); |
|
if (columns[0] > columns[1]) { |
|
items.push({ |
|
el: BI.extend({ |
|
type: "dec.masonry.block", |
|
text: entry.text, |
|
items: entry.children |
|
}, entry), |
|
left: "50%", right: 0, |
|
top: columns[1] |
|
}); |
|
columns[1] += (entry.children.length * 30 + 36); |
|
} else { |
|
items.push({ |
|
el: BI.extend({ |
|
type: "dec.masonry.block", |
|
text: entry.text, |
|
items: entry.children |
|
}, entry), |
|
left: 0, right: "50%", |
|
top: columns[0] |
|
}); |
|
columns[0] += (entry.children.length * 30 + 36); |
|
} |
|
} |
|
return items; |
|
} |
|
}, |
|
|
|
_flattenEntry: function (node) { |
|
var items = []; |
|
BI.Tree.traversal(node.children, function (index, n) { |
|
if (n.entryType !== DecCst.Entries.Entry_Type.FOLDER) { |
|
items.push(n); |
|
} |
|
}); |
|
return items; |
|
} |
|
}); |
|
BI.model("dec.model.masonry", Store); |
|
}()); |