Skip to content
This repository was archived by the owner on Mar 14, 2020. It is now read-only.

[Widget View] Implemented recent widgets feature. #301

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/assets/groups.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
"#0.Functional Groups.0.List Views"
]
}
]
],

"Recent Widgets": []
}]
11 changes: 7 additions & 4 deletions src/js/views/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@
// Should this REALLY be done here, or plugin registration in
// the "host"... using the functions mapped in widget options?
case 'model':
this._unbindADMEvents();
this._bindADMEvents(value);
if (value == ADM) {
this._unbindADMEvents();
this._bindADMEvents(value);
}
break;
default:
break;
Expand Down Expand Up @@ -110,7 +112,7 @@

// First unbind our ADMDesign modelUpdated handler, if any...
if (d && o.modelUpdated) {
d.designRoot.unbind("modelUpdated", o.modelUpdated, this);
d.unbind("modelUpdated", o.modelUpdated, this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing the "designRoot" when unbinding modelUpdated?

}

// Now unbind all ADM model event handlers, if any...
Expand Down Expand Up @@ -153,7 +155,8 @@
widget.designRoot = d;

// Finally, redraw our view since the ADMDesign root has changed
widget.refresh && widget.refresh(event, widget);
if (o.model === ADM)
widget.refresh && widget.refresh(event, widget);
}
});
})(jQuery);
2 changes: 1 addition & 1 deletion src/js/views/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@
.data('origin_node', v._origin_node);
}
widget._createTreeView(folderNode, value);
if (v._origin_node == widget._getSelected()){
if (v._origin_node === widget._getSelected()){
widget._setSelected(folderNode);
}
});
Expand Down
63 changes: 58 additions & 5 deletions src/js/views/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@
$.widget('rib.widgetView', $.rib.treeView, {

_create: function() {
var widget = this;
$.getJSON("src/assets/groups.json", function (groups) {
var processJSON, widget = this, design = ADM.getDesignRoot();

// Bind modelUpdated event handler direclty, designReset is using
// for rebind it after _setOptions();
this.options.modelUpdated = this._modelUpdatedHandler;
design.bind('modelUpdated', this._modelUpdatedHandler, this);
ADM.bind('designReset', this._designResetHandler, this);

// JSON processor
processJSON = function (groups) {
var resolveRefs = function (root, data) {
$.each(data, function(name, value) {
var refObj;
Expand All @@ -36,19 +44,64 @@
});
};
resolveRefs(groups, groups);
widget._groups = groups;
widget._setOption("model", groups);
widget.findDomNode(groups[0]['Functional Groups'])
.find('> a').trigger('click');
});
widget._getDefaultSelectedNode().find('> a').trigger('click');
}

// Get the json file and initial the tree.
$.rib.fsUtils.read(
"groups.json",
// After read the file succeed, process the JSON file direclty.
function(jsonText) {
processJSON(JSON.parse(jsonText));
},
// Read the default groups.json file after failure.
function() {
$.getJSON("src/assets/groups.json", processJSON);
}
);
this._groups = [{}];
this._selectedNode = undefined;
this.enableKeyNavigation();
return this;
},

_getDefaultSelectedNode: function() {
return this.element.find('li').first();
},

_nodeSelected: function (treeModelNode, data, domNode) {
this._selectedNode = treeModelNode;
this._setSelected(domNode);
$(':rib-paletteView').paletteView('option', "model", treeModelNode);
},

_modelUpdatedHandler: function(event, widget) {
var type, index,
recentWidgets = widget._groups[0]['Recent Widgets'];
// Check the event type and update recent objects array.
if (typeof(event) === 'object' && event.type == 'nodeAdded') {
type = event.node.getType();
index = $.inArray(type, recentWidgets);
// Remove the widget from recentWidget if the widget is exist
// in recentWidget and not the first
if (index > 0)
recentWidgets.splice(index, 1);
// Add the widget to the first of recentWidget array when the
// widget is not exist in recentWidget or after removed.
if (index < 0 || index > 0)
recentWidgets.unshift(type);
// Refresh the paletteView when it's displaying recent widgets.
if (index != 0 && widget._selectedNode == recentWidgets) {
$(':rib-paletteView').paletteView('refresh');
$.rib.fsUtils.write(
"groups.json", JSON.stringify(widget._groups)
);
}
}
},

resize: function(event, widget) {
var headerHeight = 30, resizeBarHeight = 20, used, e;
e = this.element;
Expand Down