Package Management Issue - (manifest.js)

33 views
Skip to first unread message

Daniel Quintero

unread,
Oct 28, 2013, 9:59:18 AM10/28/13
to jsclas...@googlegroups.com
Hi everyone,

Let me start by saying this library looks very promising, but at this point I'm a bit frustrated trying to get it to work properly.
Before i decided to bother anyone making a new post (probably about something that some one already had discussed before) i had a read at a few topics in here like:





I had a look at the documentation as well but so far i didn't succeed in the process of putting my project packages together.

Basically my problem is that i get a "Expected package at" ... "to define [Object]", see my full code below:


HTML:

<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Agent Bar</title>

    <link rel="stylesheet" href="bar.css" type="text/css">
    <link rel="stylesheet" href="reset.css" type="text/css">

    <script type="text/javascript" src="/api/public/js/lib/js_ninja_inheritance.js"></script>
    <script type="text/javascript" src="public/js/lib/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="/api/public/comsys-agent-bar.js"></script>
    <script type="text/javascript" src="/api/public/js/lib/jquery.atmosphere.js"></script>

    <script type="text/javascript">JSCLASS_PATH = 'public/js/lib/min'</script>
    <script type="text/javascript" src="public/js/lib/min/loader-browser.js"></script>
    <script type="text/javascript" src="public/js/src/manifest.js"></script>

    <script type="text/javascript" src="public/js/src/document.js"></script>
    <script type="text/javascript" src="public/js/src/login.js"></script>
    <script type="text/javascript" src="public/js/src/bar.js"></script>
    <script type="text/javascript" src="public/js/src/stateManager.js"></script>
</head>

manifest.js:

JS.packages(function() { with(this) {

    file(JSCLASS_PATH + '/state.js')
        .provides('JS.State')
        .requires(
            'JS.Module',
            'JS.Class'
        );

    file('public/js/src/barStatePattern.js')
        .provides('BarStatePattern')
        .requires(
            "JS.Class",
            "JS.State"
        );

}});

document.js:

var barStatePattern;

$(document).ready(function () {
    JS.require('BarStatePattern', function() {
        barStatePattern = new BarStatePattern();
        barStatePattern.disable();
        barStatePattern.enable();
    });
});



Worth mentioning that if i just include the script for class or state from jsclass library it works fine but i know thats not the way it's supposed to be handled, so where am i going wrong ???

I appreciate if someone can help me out.

Thanks.

James Coglan

unread,
Oct 28, 2013, 10:08:40 AM10/28/13
to jsclas...@googlegroups.com
On 28 October 2013 13:59, Daniel Quintero <comsys....@gmail.com> wrote:
Worth mentioning that if i just include the script for class or state from jsclass library it works fine but i know thats not the way it's supposed to be handled, so where am i going wrong ???

You don't need to define packages for the libraries included with jsclass. If you do, you're clobbering existing config and that might be what's breaking your code. 

Daniel Quintero

unread,
Oct 28, 2013, 10:56:59 AM10/28/13
to jsclas...@googlegroups.com
Hi James, i deleted definition for the "state.js" package but still i get the same error. my manifest.js is now like this:

    file('public/js/src/barStatePattern.js')
        .provides('BarStatePattern')
        .requires(
            "JS.Class",
            "JS.State"
        );

and my barStatePattern.js is as follows:

/**
 * Main class that implements the state pattern directive.
 *
 * @this {BarStatePattern}
 */
var BarStatePattern = new JS.Class({
    include: JS.State,

    initialize: function() {
        this.setState(Comsys.UserStatusEnum.LOGGED_ON);
    }
});
BarStatePattern.states({
    LOGGED_OFF: {
        disable: function() {/**/},

        enable: function() {
            initializeBar();
        }
    },

    LOGGED_ON: {
        disable: function() {/**/},

        enable: function() {
            $('#idle, #pause, #logOff')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
        }
    },

    IDLE: {
        disable: function() {
            $('#idle')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
            $('#callGroupWrapper').addClass('invisible');
        },

        enable: function() {
            $('#pause, #logOff')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
            $('#msisdn').text("No call");
        }
    },

    PAUSED: {
        disable: function() {
            $('#pause')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
        },

        enable: function() {
            $('#idle, #logOff')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
        }
    },

    FORCED_PAUSED: {
        disable: function() {
            $('#logOff')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
            $('#callGroupWrapper').addClass('invisible');
        },

        enable: function() {
            $('#idle, #pause')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
        }
    },

    RESERVED: {
        disable: function() {
            $('#idle, #pause, #logOff')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
        },

        enable: function() {
            $('#msisdn').text(Bar.StateManager.getMsisdn());

//        Make data accessible to the parent window object
            parent.sendDataToMainFrame(
                Bar.StateManager.getCallId()
            );
        }
    },

    BUSY: {
        disable: function() {
            $('#idle, #pause, #logOff, #agentCallRetrieveCommand, #agentCallTransferCommand')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
        },

        enable: function() {
            $('#agentCallConsultCommand').addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
            $('#callGroupWrapper').removeClass('invisible');
        }
    },

    WRAP_UP: {
        disable: function() {
            $('#callGroupWrapper').addClass('invisible');
            $('#destination').val('')
        },

        enable: function() {
            $('#idle, #pause, #logOff')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
        }
    },

    CALL_HOLD: {
        disable: function() {
            $('#agentCallConsultCommand')
                .removeClass('click-pointer')
                .parent()
                .removeClass('click-pointer');
        },

        enable: function() {
            $('#agentCallRetrieveCommand, #agentCallTransferCommand')
                .addClass('click-pointer')
                .parent()
                .addClass('click-pointer');
        }
    },

    SESSION_DESTROYED: {
        disable: function() {
            window.location.reload();
        },

        enable: function() {/**/}
    }
});


Hopefully you can spot where im going wrong about it because at this point i'm completely stuck :(

thanks a lot for your help!

Daniel.

James Coglan

unread,
Oct 29, 2013, 11:07:22 AM10/29/13
to jsclas...@googlegroups.com
On 28 October 2013 14:56, Daniel Quintero <comsys....@gmail.com> wrote:
Hi James, i deleted definition for the "state.js" package but still i get the same error. my manifest.js is now like this:

    file('public/js/src/barStatePattern.js')
        .provides('BarStatePattern')
        .requires(
            "JS.Class",
            "JS.State"
        );

and my barStatePattern.js is as follows:

The problem is probably that you're defining BarStatePattern with `var`. If your JS is on the same origin as the page, JS.require() will load it using XHR and then eval() it. Code run using eval() does not run in the global scope, so local variables aren't exported. Try removing the 'var', or adding `window.BarStatePattern = BarStatePattern` at the end. 

Daniel Quintero

unread,
Oct 30, 2013, 7:06:23 AM10/30/13
to jsclas...@googlegroups.com
Thank you James, it was indeed a problem of having a local scope defined for my BarStatePattern object. 
Works perfect without "var"

much appreciate it!
Reply all
Reply to author
Forward
0 new messages