Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[Widget View] Implemented recent widgets feature. #301

Open
wants to merge 1 commit into from

2 participants

@xuqingkuang

No description provided.

@xuqingkuang

The code is updated, please review.

Thx a lot! @zhizhangchen

@zhizhangchen zhizhangchen commented on the diff
src/js/views/base.js
@@ -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);
@zhizhangchen Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/widget.js
((5 lines not shown))
widget._setOption("model", groups);
- widget.findDomNode(groups[0]['Functional Groups'])
- .find('> a').trigger('click');
- });
+ widget._getRootNode().find('> a').trigger('click');
@zhizhangchen Owner

_getDefaultSelectedNode might be a better name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/widget.js
@@ -36,19 +44,65 @@
});
};
resolveRefs(groups, groups);
+ widget.treeJSON = groups;
@zhizhangchen Owner

widget._groups might be a better name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/widget.js
((10 lines not shown))
+ }
+
+ // 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.treeJSON = [{}];
+ this.selectedNode = undefined;
@zhizhangchen Owner

"_selectedNode" might be better than "selectedNode"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/widget.js
@@ -56,6 +110,34 @@
// allocate 30% of the remaining space for the filter tree
used = 2 * headerHeight + resizeBarHeight;
e.height(Math.round((e.parent().height() - used) * 0.3));
+ },
+
+ // Diable refresh action in treeView, so override the designReset
+ // handler here.
+ _designResetHandler: function(event, widget) {
@zhizhangchen Owner

Please check if "o.mode === ADM" to decide if we need to refresh in baseView instead of copying codes here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xuqingkuang

@zhizhangchen The code is updated by your comments, please review.

src/js/views/base.js
@@ -109,7 +111,7 @@
d = this.designRoot;
// First unbind our ADMDesign modelUpdated handler, if any...
- if (d && o.modelUpdated) {
+ if (d && d.designRoot && o.modelUpdated) {
@zhizhangchen Owner

d.designRoot should be this.designRoot

Please see line 114 - d = this.designRoot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/base.js
@@ -109,7 +111,7 @@
d = this.designRoot;
// First unbind our ADMDesign modelUpdated handler, if any...
- if (d && o.modelUpdated) {
+ if (d && d.designRoot && o.modelUpdated) {
d.designRoot.unbind("modelUpdated", o.modelUpdated, this);
@zhizhangchen Owner

Same comments as above

It's the original code, I didn't modify it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
src/js/views/widget.js
((40 lines not shown))
+ _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 widgetView and update groups file if the
@zhizhangchen Owner

"widgetView" should be paletteView

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@xuqingkuang

@zhizhangchen The code updated by your comments, please review.

@xuqingkuang

The code updated by your comments, please review. @zhizhangchen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 27, 2012
  1. [Widget View] Implemented recent widgets feature.

    Xuqing Kuang authored
This page is out of date. Refresh to see the latest.
View
4 src/assets/groups.json
@@ -57,5 +57,7 @@
"#0.Functional Groups.0.List Views"
]
}
- ]
+ ],
+
+ "Recent Widgets": []
}]
View
11 src/js/views/base.js
@@ -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;
@@ -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);
@zhizhangchen Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
}
// Now unbind all ADM model event handlers, if any...
@@ -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);
View
2  src/js/views/tree.js
@@ -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);
}
});
View
63 src/js/views/widget.js
@@ -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;
@@ -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;
Something went wrong with that request. Please try again.