Ivan Porto Carrero

IO(thoughts) flatMap (_.propagandize)

02

Jan
2007

I’ve Been Tagged and I Hid So Well :)

Darryl has tagged me

The idea of the tagging bit is that I don’t talk about programming but find a couple of things you don’t really know about me.

So here we go.

1) I used to be into playing volleyball and soccer (goalie) when i was a lot younger.. and I used to be in a band playing the bass. I obviously wasn’t very good in the musical side otherwise i wouldn’t be a programmer :)

2) I’m not married nor do I have a relationship at the current time. Not that I’m not interested the last couple relationships just didn’t work out.

3) I didn’t go to university, but i did start college. I think degrees are highly overrated. Passion, ambition and drive all together is much more important in my book.]

4) I wasn’t always a programmer. I’ve been a bartender/waiter in a studentbar in Antwerp. I’ve sold timesharing in Spain as an OPC and a sales rep. And in between i’ve been a junior system engineer for SGS Belgium.

5) When I was at school, I was the one with the big mouth, making jokes all the time and really walking the line of what can and can’t be done without getting into too much trouble. I didn’t get picked on really but also didn’t do much of the picking that goes against my  nature.

So these are my five things i wanted to share today. I guess now it’s my time to tag somebody :

I’m tagging Alex James - One of the smartest people I know

Another person to tag is Miel Van Opstal we started out together and he is one of my oldest friends.  Miel is workig for Microsoft as an evangelist.

Another Belgian to tag is Raoul Jacobs he knows sql server inside out as well as access

16

Dec
2006

A Scriptaculous Multi File Selector Class

For nblogr I wanted to provice a way to upload multiple files but just display one input field at a time.  So I worked out the following javascript class.

Usage :

<span style="color: rgb(0,0,255)">new</span> NBlogr.MultiSelector( <span style="color: rgb(163,21,21)">element(id)</span>, maxNumberOfFiles or -1 for unlimited );

The MultiSelector class:

NBlogr.MultiSelector = Class.create();
NBlogr.MultiSelector.prototype = {
    initialize : <span style="color: rgb(0,0,255)">function</span>(file, max){
        <span style="color: rgb(0,0,255)">this</span>.options = {
            max : -1,
            container:<span style="color: rgb(0,0,255)">null,<br></br></span>            file:<span style="color: rgb(0,0,255)">null<br></br></span>        };

        <span style="color: rgb(0,0,255)">this</span>.options.file = $(file);<br></br>        <span style="color: rgb(0,0,255)">this</span>.id = <span style="color: rgb(0,0,255)">0</span>;
        <span style="color: rgb(0,0,255)">this</span>.count=0;
        <span style="color: rgb(0,0,255)">this</span>.initializeContainer();
        <span style="color: rgb(0,0,255)">if</span>(max){
            <span style="color: rgb(0,0,255)">this</span>.options.max = max;
        }
        <span style="color: rgb(0,0,255)">else</span>{
            <span style="color: rgb(0,0,255)">this</span>.options.max = -1;
        }
    },
    initializeContainer : <span style="color: rgb(0,0,255)">function</span>(){
        <span style="color: rgb(0,0,255)">if</span>(<span style="color: rgb(0,0,255)">this</span>.options.file){
            <span style="color: rgb(0,0,255)">var</span> ele = <span style="color: rgb(0,0,255)">this</span>.options.file;
            <span style="color: rgb(0,0,255)">this</span>.options.container = Builder.node(<span style="color: rgb(163,21,21)">'div'</span>,{id:ele.id + <span style="color: rgb(163,21,21)">'_container'</span>,
                style:<span style="color: rgb(163,21,21)">'background:transparent;display:inline;width:250px;font-size:small'</span>});

            ele.parentNode.insertBefore(<span style="color: rgb(0,0,255)">this</span>.options.container,ele);
            <span style="color: rgb(0,0,255)">this</span>.options.container.appendChild(ele);

            <span style="color: rgb(0,0,255)">if</span>(!<span style="color: rgb(0,0,255)">this</span>.list){
                <span style="color: rgb(0,0,255)">this</span>.list = Builder.node(<span style="color: rgb(163,21,21)">'div'</span>,{id:ele.id+<span style="color: rgb(163,21,21)">'_list'</span>,style:<span style="color: rgb(163,21,21)">'display:block'</span>});
            }
            <span style="color: rgb(0,0,255)">this</span>.options.container.appendChild(<span style="color: rgb(0,0,255)">this</span>.list);
            <span style="color: rgb(0,0,255)">this</span>.initializeFile(ele);
        }
    },
    initializeFile:<span style="color: rgb(0,0,255)">function</span>(element){        

        <span style="color: rgb(0,0,255)">if</span>( element && element.tagName == <span style="color: rgb(163,21,21)">'INPUT'</span> && element.type == <span style="color: rgb(163,21,21)">'file'</span> ){
            element.name = <span style="color: rgb(163,21,21)">'file_'</span> + <span style="color: rgb(0,0,255)">element</span>.id;
            element.id = <span style="color: rgb(163,21,21)">'file_'</span> + <span style="color: rgb(0,0,255)"><span style="color: rgb(0,0,255)">element</span></span>.id++;


            Event.observe(element,<span style="color: rgb(163,21,21)">'change'</span>,<span style="color: rgb(0,0,255)">this</span>.addFile.bindAsEventListener(<span style="color: rgb(0,0,255)">this</span>));

            <span style="color: rgb(0,0,255)">if</span>( <span style="color: rgb(0,0,255)">this</span>.max != -1 && <span style="color: rgb(0,0,255)">this</span>.count >= <span style="color: rgb(0,0,255)">this</span>.max ){
                element.disabled = <span style="color: rgb(0,0,255)">true</span>;
            };
            <span style="color: rgb(0,0,255)">this</span>.count++;            
        } <span style="color: rgb(0,0,255)">else</span> {
            alert( <span style="color: rgb(163,21,21)">'Error: not a file input element'</span> );
        };
    },
    addFile:<span style="color: rgb(0,0,255)">function</span>(ev){
        <span style="color: rgb(0,0,255)">var</span> ele = Event.element(ev);

        <span style="color: rgb(0,0,255)">var</span> new_element = document.createElement( <span style="color: rgb(163,21,21)">'input'</span> );
        new_element.type = <span style="color: rgb(163,21,21)">'file'</span>;
        ele.parentNode.insertBefore( new_element, ele );
        <span style="color: rgb(0,0,255)">this</span>.initializeFile( new_element );
        <span style="color: rgb(0,0,255)">this</span>.addListRow( ele );
        ele.style.position = <span style="color: rgb(163,21,21)">'absolute'</span>;
        ele.style.left = <span style="color: rgb(163,21,21)">'-1000px'</span>;

        <span style="color: rgb(0,0,255)">if</span>(ev) Event.stop(ev);
    },
    removeFile:<span style="color: rgb(0,0,255)">function</span>(ev){
        <span style="color: rgb(0,0,255)">var</span> ele = Event.element(ev); 

        ele.parentNode.parentNode.removeChild( ele.parentNode );
        <span style="color: rgb(0,0,255)">this</span>.options.file.disabled = <span style="color: rgb(0,0,255)">false</span>;
        <span style="color: rgb(0,0,255)">this</span>.count--;        

        <span style="color: rgb(0,0,255)">if</span>(ev) Event.stop(ev);
    },
    addListRow : <span style="color: rgb(0,0,255)">function</span>( element ){
        <span style="color: rgb(0,0,255)">var</span> new_row_button = Builder.node(<span style="color: rgb(163,21,21)">'a'</span>,{href:<span style="color: rgb(163,21,21)">'javascript:;;'</span>,
            title:<span style="color: rgb(163,21,21)">'Remove this file from the list'</span>},<span style="color: rgb(163,21,21)">'Remove'</span>);
        <span style="color: rgb(0,0,255)">var</span> new_row = Builder.node(<span style="color: rgb(163,21,21)">'div'</span>,{element:element},[$F(element) + <span style="color: rgb(163,21,21)">' | '</span>, new_row_button]);
        Event.observe(new_row_button,<span style="color: rgb(163,21,21)">'click'</span>,<span style="color: rgb(0,0,255)">this</span>.removeFile.bindAsEventListener(<span style="color: rgb(0,0,255)">this</span>));
        <span style="color: rgb(0,0,255)">this</span>.list.appendChild( new_row );

    }
};

13

Dec
2006

Fraudulent Postal Mails From Domain Registrar

Today we got a mail from central registration service .com telling us that we need to pay 966 USD for www.vandyck.co.nz
Now I’m very sure it’s my domain name and not registered with these guys.

The company poses as a New York based company but the letter is sent from Prague. 

I just blog about it because it looks kind of official and maybe other people might not discard it.

When will I be able to put a spam filter on my regular mailbox ?

12

Dec
2006

Finally Back to Nblogr

I can finally spend a couple of days on nblogr. I hope I get enough done to have a releasable version after this time.

12

Dec
2006

Wtf ?? Ajax and the Hidden Cost of Use

In it world Sean McGrath has been talking about Ajax and the hidden cost of use.

I got to this post through Jon Udell, who has a post about ajax and automation.

Anyway the sort of arguments that Sean is using make me think he has yet to complete a good ajax application.

A common buzzword in the industry is the concept of a “front end”. In an ideal world, the front end just handles all the graphical user interface stuff while the back end does all the real work. In this ideal world, you can just bypass the front end and work with the back end directly when you want to integrate applications. Sadly, we do not live in this ideal world.

I’m going of a rant here because I thought that the whole discussion AJAX is it good vs bad? was closed about a year ago.

He obviously hasn’t seen any of the Castle or ruby implementations who do just that. For example I can unit test my complete controllers base with out running a browser.

Unless i’m really sure that an application will be used in one type of browser or it’s successor and this browser is ajax capable.. then and only then the user interface will rely on javascript for the interaction.

People then go why don’t you cache values and have javascript work it out for you the next time this gives a perceived performance benefit. There are 2 main reasons for it :

1 separation of concerns the only decision an UI can make is should I show this red or green based on a value of the object etc. But nothing else.

2 you want live data not data that is almost live (i’m taling about a system where minutes matter in the workflow) :)

Think now of web-based applications you most like to use. How are their front ends and back ends? Well, historically, they have been quite cleanly separated. After all, a web browser only has limited capabilities. Behind the scenes it is really only capable of sending two commands GET and POST to things called URLs. Everything else (slight simplification!) happens at the back end.
Ah, but that was then and this is now. Now we have AJAX and JSON and Flash and the Google Web Toolkit and Windows Presentation Foundation and…
All these things help us to make web applications easier to use. In so doing, the clean separation between front end and back end gets more and more blurred. With every blurring of the separation, application integration becomes more complex.

I guess somebody is really missing the point here a UI is just a shell over lots of services that can do the job with or without the UI on it.  All the real work is to be done in the service layer or deeper down in you app.

I think Windows Presentation Foundation says it all in its name already Presenation only whatever is not related to the presenation of your data in the UI shouldn’t be there.

What I think is going on here is that he’s affraid to take the plunge because the arguments he uses are arguments I had against building a full ajax site about 2 years ago.  I’ve set them aside.. and just do it now.

I must say that using castle has been a tremendous help for me into getting things done in the same timeframe as i would have with the classic model.

For instance I’m about to finish a project that  in a clasic model would have consisted out of 70+ very dataintensive forms. The result of using ajax a.o. technologies now has the application down to 5 forms

I still had to write the 70+ views and but not nearly as many search functions etc.  I do ajax on the AHA  principle (which means I send html snippets) because JSON and building dom nodes breaks backwards compatibility and would have slowed down development a lot.

To get to the automation bit .. I think ajax makes it much more easy to interact with the backend then the classic model would have done. There are many more options to choose from (which is kind of a dissease of our time.. too many options) and you have a much finer grained control over what passes through the pipeline in terms of bits and bytes. just pull up any http request listener and you’ll have all the things you need to replay your actions vs. parse forms and go through the html to figure out the fields etc.

Ok that’s it for my morning rant.  I just thought somebody needed to put his views into context. I have to give him that technology certainly didn’t come to a standstill over the last year so it’s getting increasingly difficult to keep up.

I’ve known a couple of really good people to give up the game this year because it’s all moving too fast in some respects or not how they want it to move. In my opinion things are indeed moving very fast at the moment.. but that’s what makes it so exciting :D

08

Dec
2006

Scriptaculous Accordion Widget

Today I needed an accordion widget. I searched the internet but didn’t really find one that was based  on scriptaculous and did what i wanted it to do and how i wanted.

You need scriptaculous for this widget. Example markup is shown in the comments. Just add the javascript to a page and it will find the accordion just fine.

I thought I’d share the code:

 

<span style="color: rgb(0,128,0)">/**
 * @author Ivan Porto Carrero
 * 
 *
 * Styles:
 * *******
 * .accordeon{
 *         border: 1px solid #1F669B;

 *        font-family: Trebuchet MS, Arial, Helvetica, sans-serif;
 *        font-size: 11px;
 *        overflow:auto;
 *    }
 * h5 {
 *     font-size:12px;
 *    padding: 3px 5px 3px 5px;
 *     margin: 0;
 *     border-style: solid none solid none;
 *     border-top-color:#BDC7E7;
 *     border-bottom-color:#a1bbe4;
 *    border-width: 1px 0px 1px 0px;
 *    color:#fff;
 *    background-color: #63699C;
 *    cursor:pointer;
 * }
 * .panel_header{
 *     color:#878285;
 *     background-color: #63699C;
 *     background:url(images/shade.gif) 0 0 repeat-x;
 * }
 * .panel{
 *     margin: 0;
 *    padding-bottom:0;
 *    border: none;
 * }
 * .panel_body{padding:5px;}
 *
 *
 * Markup:
 * *******
 * 
 * <div class="accordeon">
 *    <div id="panel1" class="panel">
 *        <h5 class="panel_header">Accordian 1 Title</h5>
 *        <div id="panel1-body" class="panel_body visible">
 *            <div>Content goes here</div>
 *        </div>
 *    </div>
 *    <div id="panel2" class="panel">
 *        <h5 class="panel_header">Accordian 2 Title</h5>
 *        <div id="panel2-body" class="panel_body">
 *            <div>Content goes here</div>
 *        </div>
 *    </div>
 *    <div id="panel3" class="panel">
 *        <h5 class="panel_header">Accordian 3 Title</h5>
 *        <div id="panel3-body" class="panel_body">
 *            <div>Content goes here</div>
 *        </div>
 *    </div>
 *    <div id="panel4" class="panel">
 *        <h5 class="panel_header">Accordian 4 Title</h5>
 *        <div id="panel4-body" class="panel_body">
 *            <div>Content goes here</div>
 *        </div>
 *    </div>
 * </div>
 */
</span>Accordeon = Class.create();
Accordeon.prototype = {
    initialize:<span style="color: rgb(0,0,255)">function</span>(element, options){
        <span style="color: rgb(0,0,255)">this</span>.options = {
            onBeforeSwitch:<span style="color: rgb(0,0,255)">null</span>,
            onAfterSwitch:<span style="color: rgb(0,0,255)">null</span>,
            activePanel:<span style="color: rgb(0,0,255)">null</span>,
            panelClass:<span style="color: rgb(163,21,21)">'panel'</span>,
            headerClass:<span style="color: rgb(163,21,21)">'panel_header'</span>,
            bodyClass: <span style="color: rgb(163,21,21)">'panel_body'</span>,
            activePanelClass:<span style="color: rgb(163,21,21)">'active'</span>,
            showAnim:<span style="color: rgb(0,0,255)">false
</span>        };
        Object.extend(<span style="color: rgb(0,0,255)">this</span>.options,options||{});        

        <span style="color: rgb(0,0,255)">this</span>.accordeon = $(element);
        <span style="color: rgb(0,0,255)">this</span>.accordeon.panels = <span style="color: rgb(0,0,255)">new</span> Array();
        <span style="color: rgb(0,0,255)">var</span> pnls = $A(<span style="color: rgb(0,0,255)">this</span>.accordeon.childNodes);
        pnls.each(
            <span style="color: rgb(0,0,255)">function</span>(pnl){

                <span style="color: rgb(0,0,255)">var</span> ele = $(pnl);

                <span style="color: rgb(0,0,255)">var</span> headers = ele.getElementsByClassName(<span style="color: rgb(0,0,255)">this</span>.options.headerClass);
                <span style="color: rgb(0,0,255)">if</span>(headers.length > 0){
                    <span style="color: rgb(0,0,255)">var</span> header = headers[0];
                    ele.header = header;
                    Event.observe(header,<span style="color: rgb(163,21,21)">'click'</span>, <span style="color: rgb(0,0,255)">this</span>.onChange.bindAsEventListener(<span style="color: rgb(0,0,255)">this</span>))
                }

                <span style="color: rgb(0,0,255)">var</span> bodies = ele.getElementsByClassName(<span style="color: rgb(0,0,255)">this</span>.options.bodyClass);
                <span style="color: rgb(0,0,255)">if</span>(bodies.length > 0){
                    <span style="color: rgb(0,0,255)">var</span> body = bodies[0];
                    ele.body = body;
                    body.hide();
                }

                <span style="color: rgb(0,0,255)">if</span>(ele.tagName.toLowerCase() == <span style="color: rgb(163,21,21)">'div'</span> && Element.hasClassName(ele,<span style="color: rgb(0,0,255)">this</span>.options.panelClass)){
                    <span style="color: rgb(0,0,255)">this</span>.accordeon.panels.push(ele);
                }
            }.bind(<span style="color: rgb(0,0,255)">this</span>)
        );
        <span style="color: rgb(0,0,255)">this</span>.setActivePanel(pnls[0],<span style="color: rgb(0,0,255)">false</span>);

    },
    onChange:<span style="color: rgb(0,0,255)">function</span>(ev){
        <span style="color: rgb(0,0,255)">var</span> ele = Event.element(ev);
        <span style="color: rgb(0,0,255)">var</span> parents = ele.ancestors();
        <span style="color: rgb(0,0,255)">var</span> panel;

        parents.each(
            <span style="color: rgb(0,0,255)">function</span>(elm){                
                <span style="color: rgb(0,0,255)">var</span> obj = $(elm);
                <span style="color: rgb(0,0,255)">if</span>(obj.hasClassName(<span style="color: rgb(0,0,255)">this</span>.options.panelClass)){
                    panel = obj;
                    <span style="color: rgb(0,0,255)">return</span>;
                }                

            }.bind(<span style="color: rgb(0,0,255)">this</span>)            
        );
        <span style="color: rgb(0,0,255)">this</span>.setActivePanel(panel,<span style="color: rgb(0,0,255)">true</span>);
    },
    setActivePanel:<span style="color: rgb(0,0,255)">function</span>(panel,showAnim){
        <span style="color: rgb(0,0,255)">if</span>(<span style="color: rgb(0,0,255)">this</span>.onBeforeSwitch)
            <span style="color: rgb(0,0,255)">this</span>.onBeforeSwitch();

        <span style="color: rgb(0,0,255)">if</span>(<span style="color: rgb(0,0,255)">this</span>.activePanel && <span style="color: rgb(0,0,255)">this</span>.activePanel.id != panel.id ){    
            <span style="color: rgb(0,0,255)">var</span> hideAnim = <span style="color: rgb(0,0,255)">null</span>;
            <span style="color: rgb(0,0,255)">if</span>(<span style="color: rgb(0,0,255)">this</span>.options.showAnim)        
                <span style="color: rgb(0,0,255)">new</span> Effect.toggle(<span style="color: rgb(0,0,255)">this</span>.activePanel.body,<span style="color: rgb(163,21,21)">'blind'</span>,{duration:0.3});
            <span style="color: rgb(0,0,255)">else
</span>                <span style="color: rgb(0,0,255)">this</span>.activePanel.body.hide();
            <span style="color: rgb(0,0,255)">this</span>._activatePanel(panel,showAnim,hideAnim);                
        }
        <span style="color: rgb(0,0,255)">else</span> <span style="color: rgb(0,0,255)">if</span> (!<span style="color: rgb(0,0,255)">this</span>.activePanel){
            <span style="color: rgb(0,0,255)">this</span>._activatePanel(panel,showAnim);
        }
        <span style="color: rgb(0,0,255)">if</span>(<span style="color: rgb(0,0,255)">this</span>.onAfterSwitch)
            <span style="color: rgb(0,0,255)">this</span>.onAfterSwitch();

    },
    _activatePanel:<span style="color: rgb(0,0,255)">function</span>(panel,showAnim,panelToHide){
        panel.body.addClassName(<span style="color: rgb(0,0,255)">this</span>.options.activePanelClass);
        <span style="color: rgb(0,0,255)">if</span>(showAnim && <span style="color: rgb(0,0,255)">this</span>.options.showAnim){
            <span style="color: rgb(0,0,255)">new</span> Effect.toggle(panel.body,<span style="color: rgb(163,21,21)">'blind'</span>,{duration:0.3});        
        }
        <span style="color: rgb(0,0,255)">else</span>{
            panel.body.show();
        }
        <span style="color: rgb(0,0,255)">this</span>.activePanel = panel;
    }
};

Accordeon.Widget = Class.create();
Accordeon.Widget.prototype = {
    initialize:<span style="color: rgb(0,0,255)">function</span>(options){
        <span style="color: rgb(0,0,255)">this</span>.options={
            containerClass:<span style="color: rgb(0,0,255)">null
</span>        };
        Object.extend(<span style="color: rgb(0,0,255)">this</span>.options,options||{});

        <span style="color: rgb(0,0,255)">this</span>.accordeons = <span style="color: rgb(0,0,255)">new</span> Array();
        $$(<span style="color: rgb(163,21,21)">'.'</span> + <span style="color: rgb(0,0,255)">this</span>.options.containerClass).each(
            <span style="color: rgb(0,0,255)">function</span>(accordeon){
                <span style="color: rgb(0,0,255)">this</span>.accordeons.push(<span style="color: rgb(0,0,255)">new</span> Accordeon(accordeon,<span style="color: rgb(0,0,255)">this</span>.options));
            }.bind(<span style="color: rgb(0,0,255)">this</span>)
        );

    }
};

Event.observe(window,<span style="color: rgb(163,21,21)">'load'</span>,<span style="color: rgb(0,0,255)">function</span>(){    
    <span style="color: rgb(0,0,255)">var</span> options = {

            panelClass:<span style="color: rgb(163,21,21)">'panel'</span>,
            headerClass:<span style="color: rgb(163,21,21)">'panel_header'</span>,
            bodyClass: <span style="color: rgb(163,21,21)">'panel_body'</span>,
            activePanelClass:<span style="color: rgb(163,21,21)">'active'</span>,
            showAnim:<span style="color: rgb(0,0,255)">true</span>,
            containerClass:<span style="color: rgb(163,21,21)">'accordeon'
</span>        };
    <span style="color: rgb(0,0,255)">new</span> Accordeon.Widget(options);
}.bindAsEventListener(<span style="color: rgb(0,0,255)">this</span>));

<font color="#008000"></font>

To top