Archive for the 'Javascript' Category

Drag & Drop Form Options with Zend Framework & Mootools

Posted January 31, 2008, 10:04am In: Zend Framework, SQL, Javascript, PHP

Recently I was working on a project that required the ability to define custom meta-data; this included categories and products, but also included a pre-determined list of countries and cities, etc.

Unfortunately, this hasn’t been tested on the latest version of the Zend Framework so it’s likely you’ll need to update your code accordingly.

We’re using version 1.2dev of MooTools

First, let’s create the controller:

I’ll skip the creation of fields and get right into the editing; I assume you’ve already added an index action and view. Our purpose is to effectively manage and modify field options, provide the ability to sort, edit and delete them, while preserving data related to the individual fields. For clarity, I will not use the view helpers for Form Elements.

Create your form and save it into your view, in my case edit-fields.php. I’ll leave it up to you to style and set form actions etc.

Then, pre-pend your javascript:

Now, before we get ahead of ourselves and worry about finding the fields, let’s the information and fields themselves - edit editFieldsAction() in your controller with the following:

Now let’s create our factory, in my case it’s MyFactory.php.

MyDomainObject::FetchCategory() validates that the requested categoryId exists. Then, the values assigned to that category. We could use $record->fetchValues() from within the rowClass instead of $obj->fetchValues($record->id), but it would more than likely just be an alias back to the factory.

Now, let’s open edit-fields.php again and add the following PHP between the UL.

An improvement to this would be to add an observer to all hyperlinks identified by class=”red”, but for simplicity, let’s leave that out. Now, our view should look something like this:

Assuming everything works, what should happen now is the list should pre-populate with previously created configuration options, we should be able to add, edit and delete those, and $_POST will override $this->options. Let’s start saving!

Edit editFieldsAction() to add some new functionality:

Now, back inside MyFactory:

It’s extra important that you pay attention to the usage of “ON DUPLICATE KEY UPDATE” - this is why we don’t have to do any fancy dancing. Additionally, we find the difference from $postArray versus what exists in the database to ensure that we delete anything that the user doesn’t want any more.

Additional steps might include the deletion of our user data when a config_value is deleted, either modifying the code itself or using the database.

More Links

Posted August 14, 2007, 7:16am In: Social Networking, Business & Clients, Web Related, Javascript, Development

I am going to write a real entry soon, I promise.

http://www.456bereastreet.com/archive/200708/microformats_book_review/
This is a great read; I’ve used Microformats in my applications and I think they are invaluable. The comments are especially useful in getting other people’s opinions.

http://ajaxian.com/archives/yui-compressor-the-latest-minification-tool
Compress those JS files! Have to try this out.

http://ajaxian.com/archives/builtwith-what-tech
Interesting. Seems a little devious to investigate what technologies are being used, but still interesting all the same.

http://www.techcrunch.com/2007/08/14/34-more-ways-to-build-your-own-social-network/
I would never use one of these tools, but it’s a good resource to have.

Who Owns the Concept if No One Signs the Papers?
Really long link, sorry.

http://yuiblog.com/blog/2007/08/13/rte-notes/
YUI looks great for simple rich text editing, haven’t tried it out yet since the YUI release. This gives me a good idea of what to expect.

mootools ResizingTextArea Component

Posted January 23, 2007, 1:25pm In: Javascript

A little while ago I saw a post by Richard McMahon regarding his post on ResizingTextArea with Prototype. However, recently I’ve grown rather fond of mootools.

As such, I’ve whipped together a brief javascript class to use mootools functions and classes, as well as added a bit more functionality.

The requirements are as follows:

  • Moo.js
  • Function.js
  • Array.js
  • String.js
  • Element.js

You can choose your build here.

There are two methods to initialize the class.

The first is to add an onfocus.

Or iterate through all textareas and add an event listener:

A demonstration can be found here:

zed23.com/demos/rsta/

All comments, suggestions and death threats are welcome.

Prototype + Zend = Good times

Posted January 18, 2007, 3:56pm In: Zend Framework, Javascript, PHP

So a quick update;

Prototype, the Javascript Library we know and love, has a new homepage at http://prototypejs.org/

And the Zend Framework has a brand new version out after last nights code freeze at http://framework.zend.com/

Quick updates

Posted November 3, 2006, 10:29am In: Javascript

Xaprb has got a fantastic article about creating input masks using javascript in HTML input fields. Definately a must read. How come I didn’t think of that?
http://www.xaprb.com/…/how-to-create-input-masks-in-html/

And Mr. Diaz has some quite cool words about “Sugar Arrays: Porting over JavaScript 1.6 Array methods”
http://www.dustindiaz.com/sugar-arrays/

WordPress Comments with Yahoo! UI

Posted October 19, 2006, 12:37am In: Javascript

jackslocum.com/…/my-wordpress-comments-system-built-with-yahoo-ui-and-yahooext/

Very cool.