jablonka.czprosek.czf

freenet-router

Subversion Repositories:
[/] [trunk/] [freenet-router/] [var/] [www/] [freenet-router/] [Framework/] [Resources/] [templates/] [UI/] [Workspace.twig] - Rev 2

Compare with Previous - Blame - Download


<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        {% block styles %}
            {% for style in styles %}
                <link rel="stylesheet" href="{{style}}" />
            {% endfor %}
        {% endblock %}
        {% block scripts %}
            {% for script in scripts %}
                <script type="text/javascript" src="{{script}}"></script>
            {% endfor %}   
                <script>                 
                    var conn;
                    var connId;
                    
                    function invokeStrongEvent(control, event)
                    {
                        
                        var eventName = "on" + event.type;
                        
                        var name = $(control).attr('id');
                        var invokedBy = connId;
                        
                        //console.log(control.style);
                        
                        $.post("{{onStrongEventLink|raw}}", {name: name, value: JSON.stringify(elementToObject(control)), event: eventName,invokedBy:invokedBy}, function(data) {
                            if (data === "reload") location.reload();
                        });
                        
                        
                        //console.log(event);
                    }                    

                    function invokeEvent(control, event)
                    {
                        var val = $(control).val();
                        if (val === "") val = $(control).text();
                        var name = $(control).attr('id');
                        var invokedBy = connId;
                        eventName = "on" + event.type;
                        //console.log(event);
                        $.post("{{onEventLink|raw}}", {name: name, value: val, event: eventName, invokedBy: invokedBy}, function(data) {
                            if (data === "reload") location.reload();
                        });
                        
                        //console.log(event);
                    }

                    function connectSocket()
                    {
                        conn = new WebSocket('ws://{{httpHost}}:80');
                        conn.onclose = function() {
                            //try to reconnect in 2 seconds
                            setTimeout(function() {
                                connectSocket();
                            }, 2000);
                        };

                        conn.onopen = function(e) {
                                                    
                            conn.send('{ "connection": { "user": "{{loggedUser.username}}", "session": "{{sessionId}}"} }');
                            //console.log("Connection established!");
                        };

                        conn.onmessage = function(e) {
                            var result = JSON.parse(e.data);  
                            
                            if (result.acceptedConnection != null)
                            {
                                connId = result.acceptedConnection;
                                return;
                            }
                            
                            var changes = JSON.parse(result.changes);
                            var invokedBy = result.invokedBy;
                            for (change in changes)
                            {
                                var objectName = changes[change].objectName;
                                switch (changes[change].type)
                                {
                                    default:
                                    case 4: 
                                        if (!$("#" + objectName).is(":focus"))
                                        {
                                            $("#" + objectName).replaceWith($(changes[change].data));
                                        }       
                                        break;
                                    case 5: 
                                        $("#" + objectName).attr(changes[change].attrName,changes[change].data);
                                        if (changes[change].attrName === "value")
                                        {
                                            $("#" + objectName).val(changes[change].data);
                                        }
                                        break;                                          
                                    case 6: 
                                        var criticalAttrs = ["left", "top","width","height"];
                                        if ((invokedBy === connId)&&($.inArray(changes[change].attrName, criticalAttrs) > -1))
                                        {
                                            break;
                                        }
                                        $("#" + objectName).css(changes[change].attrName,changes[change].data);    
                                        break;                                        
                                    case 7: 
                                        $("#" + objectName + " " + changes[change].attrName).html(changes[change].data);
                                        break;                                            
                                }
                            }
                        };
                    }

                    $(document).ready(function() {

                        connectSocket();
                    });                                    
                </script>
        {% endblock %}   
        <title>
            {% block title %}
                {{ title }}
            {% endblock %}
        </title>
        
    </head>
    <body style="width:100%;             
                height:100%;
                background-color: {{workspace.backgroundColor}};">
        {% block body %}
                {% block content %}
                    {% for window in workspace.windows %}
                        {{ include('@Phem/UI/Window.twig', {component: window}, with_context = false) }}
                    {% endfor %}
                {% endblock %}
        {% endblock %}
        {{loggedUser.username}}
    </body>
</html>

Powered by WebSVN 2.2.1