ExtJS 4 Tree dragText

Another quick one whilst it’s in my head. I was dragging between other components and the tree the other day and I wasn’t happy with the text used when dragging. So here’s a few overrides for ExtJS 4.0.7 that will let you set a dragField with your gridviewdragdrop plugin that will use the field in the model you are dragging with the dragText you provide.

This code assumes you are only ever dragging one model into the Tree.

Ext.override(Ext.view.DragZone, {
    getDragText: function() {
        if (this.dragField) {
            var fieldValue = this.dragData.records[0].get(this.dragField);
            return Ext.String.format(this.dragText, fieldValue);
        } else {
            var count = this.dragData.records.length;
            return Ext.String.format(this.dragText, count, count == 1 ? '' : 's');
        }
    }
});


Ext.override(Ext.grid.plugin.DragDrop, {
    onViewRender : function(view) {
        var me = this;

        if (me.enableDrag) {
            me.dragZone = Ext.create('Ext.view.DragZone', {
                view: view,
                ddGroup: me.dragGroup || me.ddGroup,
                dragText: me.dragText,
                dragField: me.dragField
            });
        }

        if (me.enableDrop) {
            me.dropZone = Ext.create('Ext.grid.ViewDropZone', {
                view: view,
                ddGroup: me.dropGroup || me.ddGroup
            });
        }
    }
});

Use it like this

viewConfig: {
    plugins: {
        ptype: 'gridviewdragdrop',
        ddGroup: 'TreeDD',
        enableDrop: false,
        dragText: 'Employee: {0}',
        dragField: 'fullName'
    }
},

ExtJS 4 Tree allowContainerDrop FUUUUUUUU!

So I’ve been doing some work with the ExtJS tree for the past few days.

Day one – Getting the basic tree to work reading data from my api.. magic.

Day two – updating that data using drag’n'drop from two grids of data -Separate post coming soon on this bee tee dub- a bit hellish, documentation isn’t very clear, a lot of googling and finding various answers, none of which are fully correct.

Day three – Start fixing all the drag states and structure quirks when you are not doing a simple like for like model copy. Nightmare. This also brought up something that looked like it should have been straightforward.

TreeViewDragDrop plugin has a config according to the latest documentation (4.0.7) that says ‘allowContainerDrop’ Basically if you have gone outside of a node on the tree, but still inside the container which holds the tree, you should accept the drop request and append it to the tree. At least thats what I assume it’s meant to do from reading the documentation. Doesn’t work. Long story short, it’s not been implemented and the docs are wrong. The real property has a ‘s’ at the end. ‘allowContainerDrops’ not that it matters as it does nowt.

Anyway thats my rant over as fixing it was thankfully not too difficult thanks to the trusty Ext.override function.

Read more »


ExtJS 4 checkbox empty values

Another quick one here. I’ve been using ExtJS on a new project and I’ve just noticed the default behaviour of the checkboxes in the form is a bit of a pain in the ass for working with server side.

The default behaviour is to post ‘on’ when the checkbox is selected and nothing when its empty (Some will argue like it should do). This is fine if you are just checking this flag, but it’s annoying when you are updating an object and you need to know if the user has removed the checkbox selection and you need to update the object accordingly.

I need this behaviour a lot more than I need the default so if you are in the same boat you just need to override a few config items in the checkbox class.

// We don't want the default 'on' value for submission
// causes grief on the backend.
Ext.override(Ext.form.field.Checkbox, {
    inputValue: true,
    uncheckedValue: ''
});

I find these values work perfect in conjunction with Doctrines ODM mapper for MongoDB.

I have a Override.js file in my project that I place all my overrides in thats loaded globally.

Thats it.


Zend Server RabbitMQ OSX Lion – OMFG Whyyy!!

Just a quicky so that if I have to go through this again I’ve got it here.

To install the amqp module for PHP under zend server is a nightmare when you’re kinda retarded like me. So here’s the steps.

Install Zend Server (CE).
Download rabbitmq-c using mercurial

hg clone http://hg.rabbitmq.com/rabbitmq-c
cd rabbitmq-c
hg clone http://hg.rabbitmq.com/rabbitmq-codegen codegen

Now the instructions want you to do this.

autoreconf -i && ./configure && make && sudo make install

This doesn’t work, you’ll get mad linking errors when you come to use the amqp.so file. It would appear Zend Server for OSX Lion is a bit bent and needs everything compiled in 32bit mode. So do this instead.

autoreconf -i && ./configure CFLAGS="-m32" CC="gcc-4.2" && make && sudo make install

That will install the c library in 32bit mode.

Then get pecl package for amqp-beta (Don’t install it using pecl, as you’ll get architecture incompatibility issues it would appear). So do this into a build folder somewhere.

pecl download amqp-beta
tar -xvzf amqp-0.3.1.tgz #(Correct version at time of writing, change this to whatever tgz file is downloaded)
cd amqp-0.3.1

phpize && ./configure CFLAGS="-m32" CC="gcc-4.2" --with-amqp && make && sudo make install

Then add extension=amqp.so to your php.ini file.

After all this you should hopefully see amqp listed when you run php -m


Continuous Integration with phpUnderControl – Ubuntu 10.04 setup guide.

Here is quick and dirty step by step guide to getting a basic installation of phpUnderControl up and running on Ubuntu 10.04. Fired together mainly from correcting some academic PDF on how to configure phpUnderControl You should read it also as it goes into more depth on setting up your own project. This just gets the example working. Happy CI’ing

Read more »


Doctrine 2 ODM QueryBuilder – addOr() The undocumented method of joy

OK So I was looking for away to find a document in MongoDB via Doctrine2′s DocumentMapper class and could find lots of examples on how to AND your queries together, but nothing on how to OR them. Unless I’m being blind there’s nothing in the documentation and I couldn’t find anything when hashing away with some search terms on google to find the info. Then a phrase that gets uttered at work far too often hit me… Use the source Luke So I uhhh did. Here’s a small example of how to find a document by matching one of multiple fields with your search query.

$result = $this->_dm->createQueryBuilder('HOD\Model\Person');
$result->addOr($result->expr()->field('firstName')->equals(new \MongoRegex("/^{$query}/i")))
    ->addOr($result->expr()->field('lastName')->equals(new \MongoRegex("/^{$query}/i")));
return $result->getQuery()->execute();

Enjoy


New website – goodfortunechinese.co.uk

I’ve just finished a website for the Good Fortune chinese in South Queensferry. It is a fairly simple setup, using WordPress with a design from mojo-themes.com coupled with a menu system by openmenu.com check it out here!


Juniper Network Connect, Ubuntu 10.04

Here’s a quick write up of how to get the Juniper Network Connect applet to run on Ubuntu 10.04. Here are some steps to get it installed and connected without having to visit the portal.

The hard part of the work here has been done by some clever guy called Paul D Smith who has written a script which will run the network connect applet from the command line. So rather than reinvent the wheel I’m just running through the steps you need to take to get his script working on 10.04 from a fresh install. Pauls original tutorial can be found here.

Read more »


DeferredKit & Zend_Json_Server

I was starting to think about putting together a little iPhone application to make use of an API I’d made using the Zend Framwork and Zend_Json_Server for an upcoming project. So I went hunting about for a framework that would support JSON-RPC and came across DeferredKit.

I went about attempting to include it into a simple project, and being new to iPhone development, I got nowhere the first time around. So I slept on it and decided to try again the following night. Once it was up and running, it worked like a charm for my tests! I also noticed while looking for information on the framework, that there isn’t a lot of user information out there on how to use it so incase there are other people like me looking for information on how to get up and running with it. Here’s a wee tutorial!
Read more »


Happy Birthday Tony!

Check me out, I'm old!

So @anton1r and I went out for a burn on the bikes up the
Pentlands after shitty weather conditions killed the planned trip
to Glenshee for some shred action. We took a trek through the Pentlands from Bonaly car park to Capelaw Hill. Very heavy winds made us flip the Monopoly board on going further into the hills and higher so we headed for Dreghorn to watch the soliders play pew pew on the hills. On the decent down Tony performed a spectacular maneuver by riding fast into some mud which was just a little bit too deep for the bike and ended up going arse over tit for a mud bath. Hilarious!

After that a wee trek back to Bonaly then out west to see what we could see. Not much. Anyhoo, good ride, good banter, good times! Cheers T.

It would appear I lost the GPS signal for some of this route, we did travel further, honest guv!