These are chat archives for jdubray/sam-examples

3rd
May 2016
Bang-Equal
@Bang-Equal
May 03 2016 17:48
I am trying to run the crud-blog but none of the button clicks work because "actions is not defined". I dopn'
I don't see actions in server.js but I do see it in blog.js
Jean-Jacques Dubray
@jdubray
May 03 2016 17:51
@ReketeBravo could try that repo? https://github.com/jdubray/sam-safe
Did you do npm install?
Bang-Equal
@Bang-Equal
May 03 2016 17:54
yes
Jean-Jacques Dubray
@jdubray
May 03 2016 17:54
I just tried it on my machine and it seems to work
Let me check if I pushed the latest code
Looks like the latest code is available in the repo
Bang-Equal
@Bang-Equal
May 03 2016 17:57
is it correct that server.js does not have actions?
Jean-Jacques Dubray
@jdubray
May 03 2016 17:57
yes, I implemented the actions in the browser, SAM allows to decide where the elements of the pattern are deployed
Bang-Equal
@Bang-Equal
May 03 2016 17:58
ok, I am currently running node on a Win7 machine
let me try on my macbook
Jean-Jacques Dubray
@jdubray
May 03 2016 17:58
This particular sample "presents" the results from the action to the model
// server side $.post( "http://localhost:5425/app/v1/present", data) .done(function( representation ) { $( "#representation" ).html( representation ); } );
which line is the error?
Is the error on the server?
Bang-Equal
@Bang-Equal
May 03 2016 18:00
no the error was in the browser, the click handler for the button was saying action was undefined
Jean-Jacques Dubray
@jdubray
May 03 2016 18:02
I am need to go to a meeting, but I would check in the Web console what is coming back from the server:
.done(function( representation ) {
                $( "#representation" ).html( representation );
            }
Bang-Equal
@Bang-Equal
May 03 2016 18:02
ok, thank you
Jean-Jacques Dubray
@jdubray
May 03 2016 18:03
The HTML should be wired to the blog.js actions. If you look in blog.js it should look like this:
var actions = {} ;

actions.edit = function(data) {
    data.lastEdited = {title: data.title,  description: data.description, id: data.id } ;
    present(data) ;
    return false ;
} ;

actions.save = function(data) {
    data.item = {title: data.title, description: data.description, id: data.id || null} ;
    present(data) ;
    return false ;
} ;

actions.delete = function(data) {
    data = {deletedItemId: data.id} ;
    present(data) ;
    return false ;
} ;

actions.cancel = function(data) {
    present(data) ;
    return false ;
} ;
You can also run the sample without a server, you should uncomment the client code and comment the server code
Bang-Equal
@Bang-Equal
May 03 2016 18:04
I will try
Jean-Jacques Dubray
@jdubray
May 03 2016 18:04
For instance, in blog.html:
// client side
            model.present(data) ;

            // server side
            //$.post( "http://localhost:5425/app/v1/present", data) 
            //.done(function( representation ) {
            //    $( "#representation" ).html( representation );
            //}        
            //);
sorry have to go
Bang-Equal
@Bang-Equal
May 03 2016 19:18
OK, I got it working. The problem was that I was using the wrong url in my browser. Instead of C://crud-blog/blog.html, I was using http://localhost:5425/app/v1/init
Bang-Equal
@Bang-Equal
May 03 2016 19:24
Also, I opened an issue in sam-safe repo to update the package.json "start" script.
Thank you for all of your work!
Jean-Jacques Dubray
@jdubray
May 03 2016 19:29
You are welcome, thank you for giving it a try.