<?xml version="1.0" encoding="UTF-8" ?>
<Module>
    <ModulePrefs title="Change Password" >
        <Require feature="pubsub-2"/>
    </ModulePrefs>
    <Content type="html" view="default">
        <![CDATA[

        <link rel="stylesheet" type="text/css" href="js/ui/css/main.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/smoothness/jquery-ui-1.12.1.custom.min.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/smoothness/jqueryui-themeroller.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/dialog.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap-theme.css">

        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="serverinfo.jag"></script>
        <script>
            var headID = document.getElementsByTagName("head")[0];
            var cssNode = document.createElement('link');
            cssNode.type = 'text/css';
            cssNode.rel = 'stylesheet';
            cssNode.href = PROXY_CONTEXT_PATH + '/portal/gadgets/pwd_change/js/ui/font-awesome/css/font-awesome.min.css';
            headID.appendChild(cssNode);
        </script>
        <script>
            $(function() {
                $('.max_view').click(function() {
                    gadgets.Hub.publish('org.wso2.is.dashboard', {
                        msg : 'A message from Change Password',
                        id: "pwd_change .expand-widget"
                    });
                });
            });
        </script>

        <div class='icon-key icon-key-dashboard icon-marketing-styles'></div>
        <p>Change current account password.</p>
        <p><a class='btn btn-default max_view' href=''>View details</a></p>
        ]]>
    </Content>

    <Content type="html" view="home">
        <![CDATA[
        <script type="text/javascript" src="/portal/csrf.js"></script>
        <script type="text/javascript" src="js/jquery.min.js"></script>
        <script type="text/javascript" src="js/main.js"></script>
        <script type="text/javascript" src="js/modal.js"></script>
        <script type="text/javascript" src="js/gadget.js"></script>
        <script type="text/javascript" src="serverinfo.jag"></script>

        <link rel="stylesheet" type="text/css" href="js/ui/css/main.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap.min.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap-theme.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap-missing.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/bootstrap-theme.min.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/dialog.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/smoothness/jquery-ui-1.12.1.custom.min.css">
        <link rel="stylesheet" type="text/css" href="js/ui/css/smoothness/jqueryui-themeroller.css">

        <script>
            var headID = document.getElementsByTagName("head")[0];
            var cssNode = document.createElement('link');
            cssNode.type = 'text/css';
            cssNode.rel = 'stylesheet';
            cssNode.href = PROXY_CONTEXT_PATH + '/portal/gadgets/pwd_change/js/ui/font-awesome/css/font-awesome.min.css';
            headID.appendChild(cssNode);
        </script>

        <script type="text/javascript">
            var cookie = null;
            var json = null;
            var userName = null;
            var serverUrl = window.location.host + PROXY_CONTEXT_PATH;
            $(function WindowLoad(event) {
                url = 'wss://' + serverUrl + '/dashboard/session_manager.jag';
                ws = new WebSocket(url);

                ws.onopen = function () {
                    console.log("web Socket onopen. ");
                    ws.send("First Message open");
                };
                ws.onmessage = function (event) {
                    var obj = $.parseJSON(event.data);
                    cookie = obj.cookie;
                    userName = obj.user;
                    reloadGrid();
                    if (cookie != null) {
                        drawPage();

                    }
                };
                ws.onclose = function () {
                    console.log("web Socket onclose. ");
                };
            });

            function submitUpdate() {

                var str = PROXY_CONTEXT_PATH + "/portal/gadgets/pwd_change/controllers/pwd_change/edit.jag";
                $.ajax({
                    url:str,
                    type:"POST",
                    data:$('#gadgetForm').serialize() + "&profileConfiguration=default" + "&cookie=" + cookie + "&user=" + userName
                })
                        .done(function (data) {
                         var resp = $.parseJSON(data);
                          if (resp.success == true) {
                           			cancel();
                       } else {
                           if (typeof resp.reLogin != 'undefined' && resp.reLogin == true) {
                               window.top.location.href = window.location.protocol + '//' + serverUrl + '/dashboard/logout.jag';
                           } else {
                               if (resp.message != null && resp.message.length > 0) {
                                   message({content: resp.message, type: 'error', cbk: function () {
                                   }});
                               } else {
                                   message({content: 'Error occurred while updating password.', type: 'error', cbk: function () {
                                   }});
                               }
                           }
                       }
			//message({content:'Successfully changed the password',type:'info', cbk:function(){} });

                        })
                        .fail(function () {
			message({content:'Error while changing the password',type:'error', cbk:function(){} });
                            console.log('error');

                        })
                        .always(function () {
                            console.log('completed');
                        });

            }

        </script>


        <form id="gadgetForm" class="form-horizontal">
            <div id="gadgetBody"></div>
	    <div id="message"></div>
        </form>

        ]]>
    </Content>
</Module>
