Skip to content

Commit

Permalink
Using Ext.create now everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
weskamm committed May 10, 2012
1 parent 60669c4 commit d548dfc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 44 deletions.
14 changes: 7 additions & 7 deletions examples/action/mappanel_with_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Ext.application({
var ctrl, toolbarItems = [], action, actions = {};

// ZoomToMaxExtent control, a "button" control
action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
control: new OpenLayers.Control.ZoomToMaxExtent(),
map: map,
text: "max extent",
Expand All @@ -35,7 +35,7 @@ Ext.application({

// Navigation control and DrawFeature controls
// in the same toggle group
action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "nav",
control: new OpenLayers.Control.Navigation(),
map: map,
Expand All @@ -51,7 +51,7 @@ Ext.application({
actions["nav"] = action;
toolbarItems.push(Ext.create('Ext.button.Button', action));

action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "draw poly",
control: new OpenLayers.Control.DrawFeature(vector, OpenLayers.Handler.Polygon),
map: map,
Expand All @@ -65,7 +65,7 @@ Ext.application({
actions["draw_poly"] = action;
toolbarItems.push(Ext.create('Ext.button.Button', action));

action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "draw line",
control: new OpenLayers.Control.DrawFeature(vector, OpenLayers.Handler.Path),
map: map,
Expand All @@ -81,7 +81,7 @@ Ext.application({
toolbarItems.push("-");

// SelectFeature control, a "toggle" control
action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "select",
control: new OpenLayers.Control.SelectFeature(vector, {
type: OpenLayers.Control.TYPE_TOGGLE,
Expand All @@ -100,7 +100,7 @@ Ext.application({
ctrl = new OpenLayers.Control.NavigationHistory();
map.addControl(ctrl);

action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "previous",
control: ctrl.previous,
disabled: true,
Expand All @@ -109,7 +109,7 @@ Ext.application({
actions["previous"] = action;
toolbarItems.push(Ext.create('Ext.button.Button', action));

action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
text: "next",
control: ctrl.next,
disabled: true,
Expand Down
4 changes: 2 additions & 2 deletions src/GeoExt/Action.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* Base class is [Ext.Action](http://dev.sencha.com/deploy/dev/docs/?class=Ext.Action)
*
* @example
* var action = new GeoExt.Action({
* var action = Ext.create('GeoExt.Action', {
* text: "max extent",
* control: new OpenLayers.Control.ZoomToMaxExtent(),
* map: map
* });
* var toolbar = new Ext.toolbar.Toolbar([action]);
* var toolbar = Ext.create('Ext.toolbar.Toolbar', action);
*
*/
Ext.define('GeoExt.Action', {
Expand Down
80 changes: 45 additions & 35 deletions tests/Action.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
checkHandler: checkHandler
};

action = new GeoExt.Action(cfg);
action = Ext.create('GeoExt.Action', cfg);

t.ok(action.control == ctrl,
"constructor sets control in the instance");
Expand Down Expand Up @@ -84,15 +84,18 @@
stopEvent: function() {},
button: 0
};

menu = new Ext.menu.Menu({
menu = Ext.create('Ext.menu.Menu', {
// with shadow set to its default value ("sides")
// IE throws "object: Invalid argument" exceptions
shadow: false
});
menuBtn = new Ext.button.Button({menu: menu});

tb = new Ext.toolbar.Toolbar({
menuBtn = Ext.create('Ext.button.Button', {
menu: menu
});

tb = Ext.create('Ext.toolbar.Toolbar', {
renderTo: "toolbar",
items: [menuBtn]
});
Expand All @@ -105,16 +108,17 @@
}
});
ctrl.activate();
action = new GeoExt.Action({

action = Ext.create('GeoExt.Action', {
control: ctrl,
handler: function() {
handlerCnt++;
}
});

// create button from action and it to toolbar
btn = new Ext.button.Button(action);
btn = Ext.create('Ext.button.Button', action);

tb.add(btn);

// simulate click on button
Expand All @@ -128,7 +132,7 @@
t.eq(handlerCnt, 1, "click on button calls action handler once");

// create menu item from action and it to menu
item = new Ext.menu.Item(action);
item = Ext.create('Ext.menu.Item', action);
menu.add(item);

// simulate click on menu item
Expand Down Expand Up @@ -167,16 +171,19 @@
button: 0
};

menu = new Ext.menu.Menu({
menu = Ext.create('Ext.menu.Menu', {
// with shadow set to its default value ("sides")
// IE throws "object: Invalid argument" exceptions
shadow: false
});
menuBtn = new Ext.button.Button({menu: menu});

menuBtn = Ext.create('Ext.button.Button', {
menu: menu
});

tb = new Ext.toolbar.Toolbar({
tb = Ext.create('Ext.toolbar.Toolbar', {
renderTo: "toolbar",
buttons: [menuBtn]
items: [menuBtn]
});

// the control
Expand All @@ -192,7 +199,7 @@
});
ctrl.activate();

action = new GeoExt.Action({
action = Ext.create('GeoExt.Action', {
control: ctrl,
enableToggle: true,
toggleHandler: function() {
Expand All @@ -204,7 +211,7 @@
});

// create button from action and it to toolbar
btn = new Ext.button.Button(action);
btn = Ext.create('Ext.button.Button', action);
tb.add(btn);
t.eq(btn.pressed, true, "Button initially pressed for active control");

Expand Down Expand Up @@ -232,8 +239,8 @@
t.eq(activateCnt, 1, "click again on button activates control once");
t.eq(toggleHandlerCnt, 1, "click again on button calls toggle handler once");

// create menu item from action and it to menu
item = new Ext.menu.CheckItem(action);
// create menu item from action and add it to menu
item = Ext.create('Ext.menu.CheckItem', action);
menu.add(item);

// simulate click on menu item
Expand Down Expand Up @@ -282,16 +289,19 @@
button: 0
};

menu = new Ext.menu.Menu({
menu = Ext.create('Ext.menu.Menu', {
// with shadow set to its default value ("sides")
// IE throws "object: Invalid argument" exceptions
shadow: false
});
menuBtn = new Ext.button.Button({menu: menu});

menuBtn = Ext.create('Ext.button.Button', {
menu: menu
});

tb = new Ext.toolbar.Toolbar({
tb = Ext.create('Ext.toolbar.Toolbar', {
renderTo: "toolbar",
buttons: [menuBtn]
items: [menuBtn]
});

// the controls
Expand Down Expand Up @@ -319,26 +329,26 @@
ctrl2.activate();

// the actions
action1 = new GeoExt.Action({
action1 = Ext.create('GeoExt.Action', {
control: ctrl1,
toggleGroup: "ctrl",
group: "ctrl",
pressed: false
});
action2 = new GeoExt.Action({
action2 = Ext.create('GeoExt.Action', {
control: ctrl2,
toggleGroup: "ctrl",
group: "ctrl",
pressed: true
});

// create buttons from actions and add them to toolbar
btn1 = new Ext.button.Button(action1);
btn1 = Ext.create('Ext.button.Button', action1);
tb.add(btn1);

t.eq(btn1.pressed, true, "btn1 is pressed because ctrl1 is active");

btn2 = new Ext.button.Button(action2);
btn2 = Ext.create('Ext.button.Button', action2);
tb.add(btn2);
tb.doLayout();
// Ext.ButtonToggleMgr is registered too late, so we need to fire
Expand Down Expand Up @@ -370,9 +380,9 @@
t.eq(activateCtrl2Cnt, 1, "click on btn2 activates ctrl2 once");

// create menu items from actions and them to menu
item1 = new Ext.menu.CheckItem(action1);
item1 = Ext.create('Ext.menu.CheckItem', action1);
menu.add(item1);
item2 = new Ext.menu.CheckItem(action2);
item2 = Ext.create('Ext.menu.CheckItem', action2);
menu.add(item2);

// simulate click on item1
Expand Down Expand Up @@ -409,7 +419,7 @@
var ctrl2 = new OpenLayers.Control();

// confirm that control is activated with pressed true
var act1 = new GeoExt.Action({
var act1 = Ext.create('GeoExt.Action', {
control: ctrl1,
map: map,
pressed: true,
Expand All @@ -419,7 +429,7 @@
t.eq(ctrl1.active, true, "ctrl1 activated with pressed true");

// confirm that a control is not activated with pressed false
var act2 = new GeoExt.Action({
var act2 = Ext.create('GeoExt.Action', {
control: ctrl2,
map: map,
pressed: false,
Expand All @@ -441,7 +451,7 @@
var ctrl2 = new OpenLayers.Control();

// confirm that control is activated with checked true
var act1 = new GeoExt.Action({
var act1 = Ext.create('GeoExt.Action', {
control: ctrl1,
map: map,
checked: true,
Expand All @@ -451,7 +461,7 @@
t.eq(ctrl1.active, true, "ctrl1 activated with checked true");

// confirm that a control is not activated with checked false
var act2 = new GeoExt.Action({
var act2 = Ext.create('GeoExt.Action', {
control: ctrl2,
map: map,
checked: false,
Expand All @@ -467,13 +477,13 @@
function test_deactivateOnDisable(t) {
t.plan(7);

var act1 = new GeoExt.Action({
var act1 = Ext.create('GeoExt.Action', {
control: new OpenLayers.Control(),
map: new OpenLayers.Map()
});
t.eq(act1.deactivateOnDisable, false, "false by default");

var act2 = new GeoExt.Action({
var act2 = Ext.create('GeoExt.Action', {
control: new OpenLayers.Control({active: true}),
map: new OpenLayers.Map(),
deactivateOnDisable: true
Expand All @@ -492,13 +502,13 @@
function test_activateOnEnable(t) {
t.plan(7);

var act1 = new GeoExt.Action({
var act1 = Ext.create('GeoExt.Action', {
control: new OpenLayers.Control(),
map: new OpenLayers.Map()
});
t.eq(act1.activateOnEnable, false, "false by default");

var act2 = new GeoExt.Action({
var act2 = Ext.create('GeoExt.Action', {
control: new OpenLayers.Control({active: false}),
map: new OpenLayers.Map(),
disabled: true,
Expand Down

0 comments on commit d548dfc

Please sign in to comment.