<commit_before>/**
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 */

var CTRLKEYMENU = false;
var INPROGRESSMENU = false;
var MENUCIBLE = null;
var MENUSOURCE = null;
var MENUREQ = null;
var MENUOUT = true;
var MENUOUTTIMER = false;
var XMENU, YMENU;
var OPENSUBMENU = false;
var DIVPOPUPMENU = document.createElement("div");
var MENUSOURCETOPBORDER, MENUSOURCEBOTTOMBORDER;
var MENUSOURCECLASS;
var MENUIDENTIFICATOR = false;

//include_js('WHAT/Layout/geometry.js');
//include_js('WHAT/Layout/DHTMLapi.js');
//include_js('WHAT/Layout/AnchorPosition.js');

addEvent(window, "load", function adddivpop() {
    document.body.appendChild(DIVPOPUPMENU)
});
function reqViewMenu() {
    INPROGRESSMENU = false;
    document.body.style.cursor = 'auto';
    var o = MENUCIBLE;

    if (MENUREQ.readyState == 4) {
        // only if "OK"
        //dump('readyState\n');
        if (MENUREQ.status == 200) {
            // ...processing statements go here...
            //  alert(MENUREQ.responseText);
            unglobalcursor();

            if (MENUREQ.responseXML) {
                var elts = MENUREQ.responseXML.getElementsByTagName("status");

                if (elts.length == 1) {
                    var elt = elts[0];
                    var code = elt.getAttribute("code");
                    var delay = elt.getAttribute("delay");
                    var c = elt.getAttribute("count");
                    var w = elt.getAttribute("warning");

                    if (w != '') alert(w);
                    if (code != 'OK') {
                        alert('code not OK\n' + MENUREQ.responseText);
                        return;
                    }
                    elts = MENUREQ.responseXML.getElementsByTagName("branch");
                    elt = elts[0].firstChild.nodeValue;
                    // alert(elt);
                    if (o) {
                        if (c > 0)       o.style.display = '';
                        o.style.left = '0px';
                        o.style.top = '0px';
                        o.innerHTML = elt;
                        openDocMenu(false, 'popupdoc');
                    }

                } else {
                    viewTextError();
                    //alert('no status\n'+MENUREQ.responseText);
                    return;
                }
            } else {
                viewTextError();
                //	alert('no xml\n'+MENUREQ.responseText);
                return;
            }
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                MENUREQ.statusText);
            return;
        }
    }
}
function viewTextError() {
    MENUCIBLE.innerHTML = MENUREQ.responseText;
    MENUCIBLE.style.position = 'absolute';

    MENUCIBLE.style.left = XMENU + 'px';
    MENUCIBLE.style.top = YMENU + 'px';
    MENUCIBLE.style.width = '100px';
    MENUCIBLE.style.display = '';
    setTimeout("MENUCIBLE.style.display='none'", 2000);
}
function menuSend(event, menuurl, cible, coord, barmenu) {
    if (INPROGRESSMENU) return false; // one request only
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        MENUREQ = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // branch for IE/Windows ActiveX version
        isIE = true;
        MENUREQ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (MENUREQ) {
        MENUREQ.onreadystatechange = reqViewMenu;
        MENUREQ.open("POST", menuurl, true); //'index.php?sole=Y&app=FDL&action=POPUPDOCDETAIL&id='+docid, true);
        MENUREQ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        MENUCIBLE = cible;

        globalcursor('wait');

        MENUREQ.send('');

        INPROGRESSMENU = true;
        document.body.style.cursor = 'progress';

        cible.style.left = '0px';
        cible.style.top = '0px';
        cible.style.width = '30px';
        if (barmenu) {
            cible.style.position = "fixed";
        } else {
             cible.style.position = "";
        }
        //	clipboardWait(cible);
        return true;
    }
    return false;
}

function viewmenu(event, murl, source, coord, barmenu) {
    closeDocMenu();
    CTRLKEYMENU = ctrlPushed(event);
    MENUSOURCE = source;
    if (coord) {
        XMENU = coord.x;
        YMENU = coord.y;
        if (isNetscape) {
            YMENU += 3;
        }
    } else {
        GetXY(event);
        XMENU = Xpos;
        YMENU = Ypos;
        if (isNetscape) {
            XMENU += 3;
            YMENU += 3;
        }
    }
    //   MENUSOURCE.style.borderStyle='solid';
    // MENUSOURCE.style.borderColor='black';
    //MENUSOURCE.style.borderWidth='1px';

    if (MENUSOURCE) {
        //    MENUSOURCE.style.borderTopStyle='dashed none dashed none';
        MENUSOURCETOPBORDER = MENUSOURCE.style.borderStyle;
        MENUSOURCEBOTTOMBORDER = MENUSOURCE.style.borderStyle;
        MENUSOURCECLASS = MENUSOURCE.className;
        MENUSOURCE.className = 'popupsource';

        // MENUSOURCE.style.borderTop='dashed 1px #777777';
        //MENUSOURCE.style.borderBottom='dashed 1px #777777';
    }

    menuSend(event, murl, DIVPOPUPMENU, coord, barmenu);
}

function viewsubmenu(event, murl, upobject, source, barmenu) {
    var coord = false;
    // var source=false;
    if (upobject) {
        coord = new Object();
        coord.x = AnchorPosition_getPageOffsetLeft(upobject);
        coord.y = AnchorPosition_getPageOffsetTop(upobject) + getObjectHeight(upobject);

    }

    viewmenu(event, murl, source, coord, barmenu);
}
function closeDocMenu() {
    var o = DIVPOPUPMENU;
    if (o) o.style.display = 'none';
    if (MENUSOURCE) {
        MENUSOURCE.className = MENUSOURCECLASS;
        //MENUSOURCE.style.borderTop=MENUSOURCETOPBORDER;
        // MENUSOURCE.style.borderBottom=MENUSOURCEBOTTOMBORDER;
    }
    MENUIDENTIFICATOR = false;
}
function sendMenuUrl(th, url, wname, bar, w, h) {
    if ((th.className == 'menuItem') || (th.className == 'menuItemCtrl')) {

        if ((wname == "") || (wname == "_self") || (wname == "_download")) {
            //      setTimeout('viewwait()',1000);
            if (wname != "_download") {
                globalcursor('wait');
                setTimeout('viewwait(true)', 500);
                setbodyopacity(0.5);
            }
            window.location.href = url;
        } else {
            if (bar) subwindowm(h, w, wname, url);
            else subwindow(h, w, wname, url);
        }

    }
}

function openDocMenu(event, menuid) {
    var el, x, y;
    var cy, h1, hf;

    x = XMENU;
    y = YMENU;
    if ((x == 0) && (y == 0)) {
        x = Xold;
        y = Yold;
        if ((x == 0) && (y == 0)) {
            x = 100;
            y = 100;
        }
    }

    x -= 2;
    y -= 2;

    //  closeSubMenu(menuid);
    OPENSUBMENU = false;
    activeMenuDocItem(event, menuid);

    el = document.getElementById(menuid);
    el.style.left = "0px";
    el.style.top = y + "px";
    //el.style.width  =  "100%";
    el.style.visibility = "hidden";

    // complete sub menus

    // test if it is on right of the window
    //  w2=getObjectWidth(document.body);
    w2 = getFrameWidth();
    // display right or left to maximize width
    w1 = getObjectWidth(el);

    x2 = x;
    if (x + w1 > w2) {
        if (w1 < w2) {
            x2 = w2 - w1;
        } else {
            x2 = 0;
        }
    }

    cy = (window.event) ? window.event.clientY : event.clientY;
    h1 = getObjectHeight(el);
    hf = getFrameHeight();
    if (cy + h1 > hf) {
        y = y - h1 + 4;
        if (cy - h1 < 0) y = 0;
    }
    if (h1 > hf) y = 0;
    el.style.left = x2 + "px";
    el.style.top = y + "px";
    el.style.display = "none";
    el.style.display = "";
    el.style.visibility = "visible";

    // event.stopPropagation();
    return false; // no navigator context menu
}
function openSubDocMenu(event, th, menuid) {
    var xy = getAnchorPosition(th.id);
    var dx = th.parentNode.offsetWidth;
    var el, cy, hf, hh;
    var x1, x2, w1, w2, dw;
    var x = xy.x;
    var y = xy.y;

    if (OPENSUBMENU) {
        //    OPENSUBMENU.style.display='none';
        OPENSUBMENU.style.visibility = 'hidden';
    }

    el = document.getElementById(menuid);
    OPENSUBMENU = el;
    // close sub menu before
    // closeSubMenu(th.parentNode.id);

    el = document.getElementById(menuid);
    w1 = getObjectWidth(el);
    w2 = getObjectWidth(document.body);
    x2 = x + dx;
    if (x + w1 + dx > w2) {
        if (w1 < w2) {
            x2 = x - w1;
        }
    }

    cy = (window.event) ? window.event.clientY : event.clientY;
    hf = getFrameHeight();
    h1 = getObjectHeight(el);
    hh = getObjectHeight(th);
    //  alert(h1+'-'+cy+'-'+hf+'-'+xy.y);
    if (cy + h1 > hf) y = y - h1 + hh;

    //  openMenuXY(event,menuid,x2,y);
    el.style.top = y + "px";
    el.style.left = x2 + "px";
    el.style.display = "none";
    el.style.display = "";
    el.style.visibility = "visible";
}
function menuover() {
    MENUOUT = false;
    if (MENUOUTTIMER) window.clearTimeout(MENUOUTTIMER);
    MENUOUTTIMER = false;
}

function menuout() {
    MENUOUTTIMER = window.setTimeout('closeDocMenu()', 1500);

}
function activeMenuDocItem(event, menuid) {
    //window.status="menu:"+menuid+itemid;
    // active css for animation for 'selid' object
    var o = document.getElementById(menuid);
    if (o) {
        var ta = o.getElementsByTagName("a");
        var mitem;
        var submenu;
        var menuitem;

        for (var i = 0; i < ta.length; i++) {

            //      alert(tdivid[menuid][i]);
            mitem = ta[i];
            visibility = mitem.getAttribute('visibility');
            if (visibility == 1) {
                mitem.className = 'menuItem';

            } else if (visibility == 2) {
                mitem.className = 'menuItemInvisible';

            } else if (visibility == 3) {
                if (CTRLKEYMENU) mitem.className = 'menuItemCtrl';
                else  mitem.className = 'menuItemInvisible';

            } else if (visibility == 4) {
                if (CTRLKEYMENU) mitem.className = 'menuItemCtrlDisabled';
                else  mitem.className = 'menuItemInvisible';

            } else if (visibility == 0) {
                mitem.className = 'menuItemDisabled';
                mitem.onclick = function () {
                    closeDocMenu();
                }
            }
            //      mitem.onmouseover=menuover;
            addEvent(mitem, 'mouseover', menuover);
            addEvent(mitem, 'mouseout', menuout);
        }

        // complete sub menu
        for (var i = 0; i < ta.length; i++) {

            mitem = ta[i];
            submenu = mitem.getAttribute('submenu');
            if (submenu != "") {
                sdiv = document.getElementById('popup' + submenu);
                if (sdiv) {
                    sdiv.appendChild(mitem);
                    i--;
                    menuitem = document.getElementById(submenu);
                    if (menuitem) {
                        if (mitem.className == 'menuItem' || mitem.className == 'menuItemDisabled') menuitem.className = 'menuItem';
                        else if (CTRLKEYMENU && (mitem.className != 'menuItemInvisible')) menuitem.className = 'menuItem';
                    }
                }
            }
        }

    }

}
<commit_msg>add z-Index to popup menu (refs #3923)<commit_after>/**
 * @author Anakeen
 * @license http://www.fsf.org/licensing/licenses/agpl-3.0.html GNU Affero General Public License
 */

var CTRLKEYMENU = false;
var INPROGRESSMENU = false;
var MENUCIBLE = null;
var MENUSOURCE = null;
var MENUREQ = null;
var MENUOUT = true;
var MENUOUTTIMER = false;
var XMENU, YMENU;
var OPENSUBMENU = false;
var DIVPOPUPMENU = document.createElement("div");
var MENUSOURCETOPBORDER, MENUSOURCEBOTTOMBORDER;
var MENUSOURCECLASS;
var MENUIDENTIFICATOR = false;

//include_js('WHAT/Layout/geometry.js');
//include_js('WHAT/Layout/DHTMLapi.js');
//include_js('WHAT/Layout/AnchorPosition.js');

addEvent(window, "load", function adddivpop() {
    document.body.appendChild(DIVPOPUPMENU)
});
function reqViewMenu() {
    INPROGRESSMENU = false;
    document.body.style.cursor = 'auto';
    var o = MENUCIBLE;

    if (MENUREQ.readyState == 4) {
        // only if "OK"
        //dump('readyState\n');
        if (MENUREQ.status == 200) {
            // ...processing statements go here...
            //  alert(MENUREQ.responseText);
            unglobalcursor();

            if (MENUREQ.responseXML) {
                var elts = MENUREQ.responseXML.getElementsByTagName("status");

                if (elts.length == 1) {
                    var elt = elts[0];
                    var code = elt.getAttribute("code");
                    var delay = elt.getAttribute("delay");
                    var c = elt.getAttribute("count");
                    var w = elt.getAttribute("warning");

                    if (w != '') alert(w);
                    if (code != 'OK') {
                        alert('code not OK\n' + MENUREQ.responseText);
                        return;
                    }
                    elts = MENUREQ.responseXML.getElementsByTagName("branch");
                    elt = elts[0].firstChild.nodeValue;
                    // alert(elt);
                    if (o) {
                        if (c > 0)       o.style.display = '';
                        o.style.left = '0px';
                        o.style.top = '0px';
                        o.innerHTML = elt;
                        openDocMenu(false, 'popupdoc');
                    }

                } else {
                    viewTextError();
                    //alert('no status\n'+MENUREQ.responseText);
                    return;
                }
            } else {
                viewTextError();
                //	alert('no xml\n'+MENUREQ.responseText);
                return;
            }
        } else {
            alert("There was a problem retrieving the XML data:\n" +
                MENUREQ.statusText);
            return;
        }
    }
}
function viewTextError() {
    MENUCIBLE.innerHTML = MENUREQ.responseText;
    MENUCIBLE.style.position = 'absolute';

    MENUCIBLE.style.left = XMENU + 'px';
    MENUCIBLE.style.top = YMENU + 'px';
    MENUCIBLE.style.width = '100px';
    MENUCIBLE.style.display = '';
    setTimeout("MENUCIBLE.style.display='none'", 2000);
}
function menuSend(event, menuurl, cible, coord, barmenu) {
    if (INPROGRESSMENU) return false; // one request only
    // branch for native XMLHttpRequest object
    if (window.XMLHttpRequest) {
        MENUREQ = new XMLHttpRequest();
    } else if (window.ActiveXObject) {
        // branch for IE/Windows ActiveX version
        isIE = true;
        MENUREQ = new ActiveXObject("Microsoft.XMLHTTP");
    }
    if (MENUREQ) {
        MENUREQ.onreadystatechange = reqViewMenu;
        MENUREQ.open("POST", menuurl, true); //'index.php?sole=Y&app=FDL&action=POPUPDOCDETAIL&id='+docid, true);
        MENUREQ.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        MENUCIBLE = cible;

        globalcursor('wait');

        MENUREQ.send('');

        INPROGRESSMENU = true;
        document.body.style.cursor = 'progress';

        cible.style.left = '0px';
        cible.style.top = '0px';
        cible.style.width = '30px';
        if (barmenu) {
            cible.style.position = "fixed";
            cible.style.zIndex = "2";
        } else {
             cible.style.position = "";
        }
        //	clipboardWait(cible);
        return true;
    }
    return false;
}

function viewmenu(event, murl, source, coord, barmenu) {
    closeDocMenu();
    CTRLKEYMENU = ctrlPushed(event);
    MENUSOURCE = source;
    if (coord) {
        XMENU = coord.x;
        YMENU = coord.y;
        if (isNetscape) {
            YMENU += 3;
        }
    } else {
        GetXY(event);
        XMENU = Xpos;
        YMENU = Ypos;
        if (isNetscape) {
            XMENU += 3;
            YMENU += 3;
        }
    }
    //   MENUSOURCE.style.borderStyle='solid';
    // MENUSOURCE.style.borderColor='black';
    //MENUSOURCE.style.borderWidth='1px';

    if (MENUSOURCE) {
        //    MENUSOURCE.style.borderTopStyle='dashed none dashed none';
        MENUSOURCETOPBORDER = MENUSOURCE.style.borderStyle;
        MENUSOURCEBOTTOMBORDER = MENUSOURCE.style.borderStyle;
        MENUSOURCECLASS = MENUSOURCE.className;
        MENUSOURCE.className = 'popupsource';

        // MENUSOURCE.style.borderTop='dashed 1px #777777';
        //MENUSOURCE.style.borderBottom='dashed 1px #777777';
    }

    menuSend(event, murl, DIVPOPUPMENU, coord, barmenu);
}

function viewsubmenu(event, murl, upobject, source, barmenu) {
    var coord = false;
    // var source=false;
    if (upobject) {
        coord = new Object();
        coord.x = AnchorPosition_getPageOffsetLeft(upobject);
        coord.y = AnchorPosition_getPageOffsetTop(upobject) + getObjectHeight(upobject);

    }

    viewmenu(event, murl, source, coord, barmenu);
}
function closeDocMenu() {
    var o = DIVPOPUPMENU;
    if (o) o.style.display = 'none';
    if (MENUSOURCE) {
        MENUSOURCE.className = MENUSOURCECLASS;
        //MENUSOURCE.style.borderTop=MENUSOURCETOPBORDER;
        // MENUSOURCE.style.borderBottom=MENUSOURCEBOTTOMBORDER;
    }
    MENUIDENTIFICATOR = false;
}
function sendMenuUrl(th, url, wname, bar, w, h) {
    if ((th.className == 'menuItem') || (th.className == 'menuItemCtrl')) {

        if ((wname == "") || (wname == "_self") || (wname == "_download")) {
            //      setTimeout('viewwait()',1000);
            if (wname != "_download") {
                globalcursor('wait');
                setTimeout('viewwait(true)', 500);
                setbodyopacity(0.5);
            }
            window.location.href = url;
        } else {
            if (bar) subwindowm(h, w, wname, url);
            else subwindow(h, w, wname, url);
        }

    }
}

function openDocMenu(event, menuid) {
    var el, x, y;
    var cy, h1, hf;

    x = XMENU;
    y = YMENU;
    if ((x == 0) && (y == 0)) {
        x = Xold;
        y = Yold;
        if ((x == 0) && (y == 0)) {
            x = 100;
            y = 100;
        }
    }

    x -= 2;
    y -= 2;

    //  closeSubMenu(menuid);
    OPENSUBMENU = false;
    activeMenuDocItem(event, menuid);

    el = document.getElementById(menuid);
    el.style.left = "0px";
    el.style.top = y + "px";
    //el.style.width  =  "100%";
    el.style.visibility = "hidden";

    // complete sub menus

    // test if it is on right of the window
    //  w2=getObjectWidth(document.body);
    w2 = getFrameWidth();
    // display right or left to maximize width
    w1 = getObjectWidth(el);

    x2 = x;
    if (x + w1 > w2) {
        if (w1 < w2) {
            x2 = w2 - w1;
        } else {
            x2 = 0;
        }
    }

    cy = (window.event) ? window.event.clientY : event.clientY;
    h1 = getObjectHeight(el);
    hf = getFrameHeight();
    if (cy + h1 > hf) {
        y = y - h1 + 4;
        if (cy - h1 < 0) y = 0;
    }
    if (h1 > hf) y = 0;
    el.style.left = x2 + "px";
    el.style.top = y + "px";
    el.style.display = "none";
    el.style.display = "";
    el.style.visibility = "visible";

    // event.stopPropagation();
    return false; // no navigator context menu
}
function openSubDocMenu(event, th, menuid) {
    var xy = getAnchorPosition(th.id);
    var dx = th.parentNode.offsetWidth;
    var el, cy, hf, hh;
    var x1, x2, w1, w2, dw;
    var x = xy.x;
    var y = xy.y;

    if (OPENSUBMENU) {
        //    OPENSUBMENU.style.display='none';
        OPENSUBMENU.style.visibility = 'hidden';
    }

    el = document.getElementById(menuid);
    OPENSUBMENU = el;
    // close sub menu before
    // closeSubMenu(th.parentNode.id);

    el = document.getElementById(menuid);
    w1 = getObjectWidth(el);
    w2 = getObjectWidth(document.body);
    x2 = x + dx;
    if (x + w1 + dx > w2) {
        if (w1 < w2) {
            x2 = x - w1;
        }
    }

    cy = (window.event) ? window.event.clientY : event.clientY;
    hf = getFrameHeight();
    h1 = getObjectHeight(el);
    hh = getObjectHeight(th);
    //  alert(h1+'-'+cy+'-'+hf+'-'+xy.y);
    if (cy + h1 > hf) y = y - h1 + hh;

    //  openMenuXY(event,menuid,x2,y);
    el.style.top = y + "px";
    el.style.left = x2 + "px";
    el.style.display = "none";
    el.style.display = "";
    el.style.visibility = "visible";
}
function menuover() {
    MENUOUT = false;
    if (MENUOUTTIMER) window.clearTimeout(MENUOUTTIMER);
    MENUOUTTIMER = false;
}

function menuout() {
    MENUOUTTIMER = window.setTimeout('closeDocMenu()', 1500);

}
function activeMenuDocItem(event, menuid) {
    //window.status="menu:"+menuid+itemid;
    // active css for animation for 'selid' object
    var o = document.getElementById(menuid);
    if (o) {
        var ta = o.getElementsByTagName("a");
        var mitem;
        var submenu;
        var menuitem;

        for (var i = 0; i < ta.length; i++) {

            //      alert(tdivid[menuid][i]);
            mitem = ta[i];
            visibility = mitem.getAttribute('visibility');
            if (visibility == 1) {
                mitem.className = 'menuItem';

            } else if (visibility == 2) {
                mitem.className = 'menuItemInvisible';

            } else if (visibility == 3) {
                if (CTRLKEYMENU) mitem.className = 'menuItemCtrl';
                else  mitem.className = 'menuItemInvisible';

            } else if (visibility == 4) {
                if (CTRLKEYMENU) mitem.className = 'menuItemCtrlDisabled';
                else  mitem.className = 'menuItemInvisible';

            } else if (visibility == 0) {
                mitem.className = 'menuItemDisabled';
                mitem.onclick = function () {
                    closeDocMenu();
                }
            }
            //      mitem.onmouseover=menuover;
            addEvent(mitem, 'mouseover', menuover);
            addEvent(mitem, 'mouseout', menuout);
        }

        // complete sub menu
        for (var i = 0; i < ta.length; i++) {

            mitem = ta[i];
            submenu = mitem.getAttribute('submenu');
            if (submenu != "") {
                sdiv = document.getElementById('popup' + submenu);
                if (sdiv) {
                    sdiv.appendChild(mitem);
                    i--;
                    menuitem = document.getElementById(submenu);
                    if (menuitem) {
                        if (mitem.className == 'menuItem' || mitem.className == 'menuItemDisabled') menuitem.className = 'menuItem';
                        else if (CTRLKEYMENU && (mitem.className != 'menuItemInvisible')) menuitem.className = 'menuItem';
                    }
                }
            }
        }

    }

}
<|endoftext|>


<commit_before>$(document).ready(function () {

    $("#content-box").fadeIn("slow");

    $(".city-button").on('click', function () {
        var activeCity = $(this).parent().attr("Id");
        GetCompanyAjax(activeCity);
        $(".company-div").fadeIn("slow");
    });

    $(".city-button").click(function () {
        $(".company-div").remove();
    });

    $("body").on("click", ".company-button", function () {
        var id = $(this).parent().attr("Id");
        console.log(id);
    });

});<commit_msg>DOM fades away on company button click<commit_after>$(document).ready(function () {

    $("#content-box").fadeIn("slow");

    $(".city-button").on('click', function () {
        var activeCity = $(this).parent().attr("Id");
        GetCompanyAjax(activeCity);
        $(".company-div").fadeIn("slow");
    });

    $(".city-button").click(function () {
        $(".company-div").remove();
    });

    $("body").on("click", ".company-button", function () {
        var id = $(this).parent().attr("Id");
        $("body").fadeOut("slow");
    });

});<|endoftext|>


<commit_before>/*******************************************************************************
 *  Code contributed to the webinos project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	 http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright 2011 Alexander Futasz, Fraunhofer FOKUS
 ******************************************************************************/

describe('common.RPC', function() {
	var webinos = require("find-dependencies")(__dirname);

	var Registry = webinos.global.require(webinos.global.rpc.location, "lib/registry").Registry;
	var registry;
	var RPCHandler = webinos.global.require(webinos.global.rpc.location).RPCHandler;
	var rpcHandler;

	beforeEach(function() {
		registry = new Registry({});
		rpcHandler = new RPCHandler(undefined, registry);
	});

	describe('rpcHandler', function() {

		it('RPCHandler is exported from node module', function() {
			expect(RPCHandler).toEqual(jasmine.any(Function));
		});

		it('RPCHandler object instantiated', function() {
			expect(rpcHandler).toBeDefined();
		});

		it('has createRPC function', function() {
			expect(rpcHandler.createRPC).toEqual(jasmine.any(Function));
		});

		it('has executeRPC function', function() {
			expect(rpcHandler.executeRPC).toEqual(jasmine.any(Function));
		});

		it('has registerCallbackObject function', function() {
			expect(rpcHandler.registerCallbackObject).toEqual(jasmine.any(Function));
		});

		it('has registerCallbackObject function', function() {
			expect(rpcHandler.registerCallbackObject).toEqual(jasmine.any(Function));
		});

		it('createRPC with service as string type', function() {
			var rpc = rpcHandler.createRPC('Service', 'functionName', [1]);
			expect(rpc).toEqual(jasmine.any(Object));

			expect(rpc.jsonrpc).toBeDefined();
			expect(rpc.jsonrpc).toEqual('2.0');

			expect(rpc.id).toBeDefined();
			expect(rpc.id).toEqual(jasmine.any(String));

			expect(rpc.method).toBeDefined();
			expect(rpc.method).toEqual(jasmine.any(String));

			expect(rpc.params).toBeDefined();
			expect(rpc.params).toEqual(jasmine.any(Object));
		});

		it('createRPC with service as RPCWebinosService', function() {
			var service = new RPCWebinosService();
			var rpc = rpcHandler.createRPC(service, 'functionName', [1]);
			expect(rpc).toEqual(jasmine.any(Object));

			expect(rpc.jsonrpc).toBeDefined();
			expect(rpc.jsonrpc).toEqual('2.0');

			expect(rpc.id).toBeDefined();
			expect(rpc.id).toEqual(jasmine.any(String));

			expect(rpc.method).toBeDefined();
			expect(rpc.method).toEqual(jasmine.any(String));

			expect(rpc.serviceAddress).toBeDefined();

			expect(rpc.params).toBeDefined();
			expect(rpc.params).toEqual(jasmine.any(Object));
		});

	});

	describe('RPC service registration', function() {
		var service;
		var rpc;

		beforeEach(function() {
			service = new RPCWebinosService();
			service.api = 'prop-api';
			service.displayName = 'prop-displayName';
			service.description = 'prop-description';
			rpc = rpcHandler.createRPC(service, 'functionName', [1]);
		});

		it('Registry is exported from node module', function() {
			expect(Registry).toEqual(jasmine.any(Function));
		});

		it('has registerObject function', function() {
			expect(registry.registerObject).toEqual(jasmine.any(Function));
		});

		it('has unregisterObject function', function() {
			expect(registry.unregisterObject).toEqual(jasmine.any(Function));
		});

		it('has no registered services initially', function() {
			expect(Object.keys(registry.objects).length).toEqual(0);
		});

		it('has exactly one registered service after registering', function() {
			registry.registerObject(service);
			expect(Object.keys(registry.objects).length).toEqual(1);
		});

		it('has no registered services after unregistering', function() {
			registry.registerObject(service);
			registry.unregisterObject(service);
			expect(Object.keys(registry.objects).length).toEqual(0);
		});

		it ('can create 2 instance of the same services', function() {
		    secondService = new RPCWebinosService();
			secondService.api = service.api;
			secondService.displayName = service.displayName;
			secondService.description = service.description;

			registry.registerObject(service);
			expect(Object.keys(registry.objects['prop-api']).length).toEqual(1);

			registry.registerObject(secondService);
			expect(Object.keys(registry.objects['prop-api']).length).toEqual(2);

			registry.unregisterObject(service);
			registry.unregisterObject(secondService);
		});

	});

	describe('RPC service request and response', function() {
		var service;

		beforeEach(function() {
			// create and register mock service
			var MockService = function(privRpcHandler, params) {
				this.base = RPCWebinosService;
				this.base({
					api: 'prop-api',
					displayName: 'prop-displayName',
					description: 'prop-description'
				});
				this.testListen = function(params, success, error, objRef) {
					var rpc = rpcHandler.createRPC(objRef, 'onEvent', {testProp: 42});
					rpcHandler.executeRPC(rpc);
				};
			};
			MockService.prototype = new RPCWebinosService();
			MockService.prototype.testSuccess = function(params, success, error, objRef) {
				// tests success callback provided by rpc.js
				success();
			};
			MockService.prototype.testError = function(params, success, error, objRef) {
				// tests error callback provided by rpc.js
				error();
			};
			service = new MockService();
			registry.registerObject(service);

			// use our own message handler write function, usually this would
			// write the request out to the remote peer
			var msgHandler = {
					write: function(rpc) {
						rpcHandler.handleMessage(rpc);
					}
			};
			rpcHandler.setMessageHandler(msgHandler);
		});

		it('with successfull response', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testSuccess', [1]);
			rpcHandler.executeRPC(rpc);

			// request
			expect(rpcHandler.handleMessage).toHaveBeenCalled();
			expect(rpcHandler.handleMessage.calls[0].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[0].args[0].method).toBeDefined();
			expect(rpcHandler.handleMessage.calls[0].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[0].args[0].params).toBeDefined();

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].result).toBeDefined();

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);
		});

		it('with error response', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testError', [1]);
			rpcHandler.executeRPC(rpc);

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].error).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].error.code).toEqual(-31000);

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);
		});

		it('with successful responce for client side listener pattern', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testListen', [1]);
			rpc.fromObjectRef = 2342; // this is totally a unique id

			// create a temporary webinos service for our callback onEvent
			var callback = new RPCWebinosService({api:rpc.fromObjectRef});
			callback.onEvent = function (){}; // empty, using spyOn instead
			spyOn(callback, 'onEvent');
			rpcHandler.registerCallbackObject(callback);
			rpcHandler.executeRPC(rpc);

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);

			expect(callback.onEvent).toHaveBeenCalled();
			expect(callback.onEvent.calls[0].args[0].testProp).toEqual(42);
		});
	});
});
<commit_msg>Removes the corresponding test case<commit_after>/*******************************************************************************
 *  Code contributed to the webinos project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *	 http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Copyright 2011 Alexander Futasz, Fraunhofer FOKUS
 ******************************************************************************/

describe('common.RPC', function() {
	var webinos = require("find-dependencies")(__dirname);

	var Registry = webinos.global.require(webinos.global.rpc.location, "lib/registry").Registry;
	var registry;
	var RPCHandler = webinos.global.require(webinos.global.rpc.location).RPCHandler;
	var rpcHandler;

	beforeEach(function() {
		registry = new Registry({});
		rpcHandler = new RPCHandler(undefined, registry);
	});

	describe('rpcHandler', function() {

		it('RPCHandler is exported from node module', function() {
			expect(RPCHandler).toEqual(jasmine.any(Function));
		});

		it('RPCHandler object instantiated', function() {
			expect(rpcHandler).toBeDefined();
		});

		it('has createRPC function', function() {
			expect(rpcHandler.createRPC).toEqual(jasmine.any(Function));
		});

		it('has executeRPC function', function() {
			expect(rpcHandler.executeRPC).toEqual(jasmine.any(Function));
		});

		it('has registerCallbackObject function', function() {
			expect(rpcHandler.registerCallbackObject).toEqual(jasmine.any(Function));
		});

		it('has registerCallbackObject function', function() {
			expect(rpcHandler.registerCallbackObject).toEqual(jasmine.any(Function));
		});

		it('createRPC with service as string type', function() {
			var rpc = rpcHandler.createRPC('Service', 'functionName', [1]);
			expect(rpc).toEqual(jasmine.any(Object));

			expect(rpc.jsonrpc).toBeDefined();
			expect(rpc.jsonrpc).toEqual('2.0');

			expect(rpc.id).toBeDefined();
			expect(rpc.id).toEqual(jasmine.any(String));

			expect(rpc.method).toBeDefined();
			expect(rpc.method).toEqual(jasmine.any(String));

			expect(rpc.params).toBeDefined();
			expect(rpc.params).toEqual(jasmine.any(Object));
		});

		it('createRPC with service as RPCWebinosService', function() {
			var service = new RPCWebinosService();
			var rpc = rpcHandler.createRPC(service, 'functionName', [1]);
			expect(rpc).toEqual(jasmine.any(Object));

			expect(rpc.jsonrpc).toBeDefined();
			expect(rpc.jsonrpc).toEqual('2.0');

			expect(rpc.id).toBeDefined();
			expect(rpc.id).toEqual(jasmine.any(String));

			expect(rpc.method).toBeDefined();
			expect(rpc.method).toEqual(jasmine.any(String));

			expect(rpc.serviceAddress).toBeDefined();

			expect(rpc.params).toBeDefined();
			expect(rpc.params).toEqual(jasmine.any(Object));
		});

	});

	describe('RPC service registration', function() {
		var service;
		var rpc;

		beforeEach(function() {
			service = new RPCWebinosService();
			service.api = 'prop-api';
			service.displayName = 'prop-displayName';
			service.description = 'prop-description';
			rpc = rpcHandler.createRPC(service, 'functionName', [1]);
		});

		it('Registry is exported from node module', function() {
			expect(Registry).toEqual(jasmine.any(Function));
		});

		it('has registerObject function', function() {
			expect(registry.registerObject).toEqual(jasmine.any(Function));
		});

		it('has unregisterObject function', function() {
			expect(registry.unregisterObject).toEqual(jasmine.any(Function));
		});

		it('has no registered services initially', function() {
			expect(Object.keys(registry.objects).length).toEqual(0);
		});

		it('has exactly one registered service after registering', function() {
			registry.registerObject(service);
			expect(Object.keys(registry.objects).length).toEqual(1);
		});

		it('has no registered services after unregistering', function() {
			registry.registerObject(service);
			registry.unregisterObject(service);
			expect(Object.keys(registry.objects).length).toEqual(0);
		});

	});

	describe('RPC service request and response', function() {
		var service;

		beforeEach(function() {
			// create and register mock service
			var MockService = function(privRpcHandler, params) {
				this.base = RPCWebinosService;
				this.base({
					api: 'prop-api',
					displayName: 'prop-displayName',
					description: 'prop-description'
				});
				this.testListen = function(params, success, error, objRef) {
					var rpc = rpcHandler.createRPC(objRef, 'onEvent', {testProp: 42});
					rpcHandler.executeRPC(rpc);
				};
			};
			MockService.prototype = new RPCWebinosService();
			MockService.prototype.testSuccess = function(params, success, error, objRef) {
				// tests success callback provided by rpc.js
				success();
			};
			MockService.prototype.testError = function(params, success, error, objRef) {
				// tests error callback provided by rpc.js
				error();
			};
			service = new MockService();
			registry.registerObject(service);

			// use our own message handler write function, usually this would
			// write the request out to the remote peer
			var msgHandler = {
					write: function(rpc) {
						rpcHandler.handleMessage(rpc);
					}
			};
			rpcHandler.setMessageHandler(msgHandler);
		});

		it('with successfull response', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testSuccess', [1]);
			rpcHandler.executeRPC(rpc);

			// request
			expect(rpcHandler.handleMessage).toHaveBeenCalled();
			expect(rpcHandler.handleMessage.calls[0].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[0].args[0].method).toBeDefined();
			expect(rpcHandler.handleMessage.calls[0].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[0].args[0].params).toBeDefined();

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].result).toBeDefined();

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);
		});

		it('with error response', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testError', [1]);
			rpcHandler.executeRPC(rpc);

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].error).toBeDefined();
			expect(rpcHandler.handleMessage.calls[1].args[0].error.code).toEqual(-31000);

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);
		});

		it('with successful responce for client side listener pattern', function() {
			spyOn(rpcHandler, 'handleMessage').andCallThrough();
			spyOn(rpcHandler, 'executeRPC').andCallThrough();

			var rpc = rpcHandler.createRPC(service, 'testListen', [1]);
			rpc.fromObjectRef = 2342; // this is totally a unique id

			// create a temporary webinos service for our callback onEvent
			var callback = new RPCWebinosService({api:rpc.fromObjectRef});
			callback.onEvent = function (){}; // empty, using spyOn instead
			spyOn(callback, 'onEvent');
			rpcHandler.registerCallbackObject(callback);
			rpcHandler.executeRPC(rpc);

			// response
			expect(rpcHandler.handleMessage.calls[1].args.length).toEqual(1);
			expect(rpcHandler.handleMessage.calls[1].args[0].id).toBeDefined();

			// called once for request and once for response
			expect(rpcHandler.executeRPC.calls.length).toEqual(2);

			expect(callback.onEvent).toHaveBeenCalled();
			expect(callback.onEvent.calls[0].args[0].testProp).toEqual(42);
		});
	});
});
<|endoftext|>


<commit_before>(function(){
    angular.module('app').controller('SentencesListsDownloadCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {

        var rootUrl = get_tatoeba_root_url();

        $scope.export = {};
        $scope.preparingDownload = false;

        function startDownload() {
            var filename = encodeURIComponent($scope.export.pretty_filename);
            window.location = rootUrl + "/exports/download/" + $scope.export.id + "/" + filename;
            $scope.preparingDownload = false;
        }

        $scope.tryToDownloadList = function() {
            $timeout.cancel($scope.tryAgainPromise);
            $scope.tryAgainPromise = $timeout(function() {
                $http.get(rootUrl + "/exports/get/" + $scope.export.id)
                .then(
                    function(response) {
                        $scope.export = response.data.export;
                        if ($scope.export.status == 'online') {
                            startDownload();
                        } else {
                            $scope.tryToDownloadList();
                        }
                    },
                    function() {
                        $scope.tryToDownloadList();
                    }
                );
            }, 5000);
        }

        $scope.addListExport = function (listId) {
            $scope.preparingDownload = true;
            var fields = [];
            if ($scope.showid) {
                fields.push('id');
            }
            fields.push('text');
            if ($scope.trans_lang != 'none') {
                fields.push('trans_text');
            }
            $http.post(rootUrl + "/exports/add", {
                     'type': 'list',
                     'list_id': listId,
                     'fields': fields,
                     'trans_lang': $scope.trans_lang,
                 })
                 .then(
                    function(response) {
                        $scope.export = response.data.export;
                        $scope.tryToDownloadList();
                    },
                    function(errorResponse) {
                        $scope.preparingDownload = false;
                    }
                 );
        };
    }]);
})();
<commit_msg>Hide download loading icon if export failed<commit_after>(function(){
    angular.module('app').controller('SentencesListsDownloadCtrl', ['$scope', '$http', '$timeout', function ($scope, $http, $timeout) {

        var rootUrl = get_tatoeba_root_url();

        $scope.export = {};
        $scope.preparingDownload = false;

        function startDownload() {
            var filename = encodeURIComponent($scope.export.pretty_filename);
            window.location = rootUrl + "/exports/download/" + $scope.export.id + "/" + filename;
            $scope.preparingDownload = false;
        }

        $scope.tryToDownloadList = function() {
            $timeout.cancel($scope.tryAgainPromise);
            $scope.tryAgainPromise = $timeout(function() {
                $http.get(rootUrl + "/exports/get/" + $scope.export.id)
                .then(
                    function(response) {
                        $scope.export = response.data.export;
                        if ($scope.export.status == 'online') {
                            startDownload();
                        } else if ($scope.export.status == 'failed') {
                            $scope.preparingDownload = false;
                        } else {
                            $scope.tryToDownloadList();
                        }
                    },
                    function() {
                        $scope.preparingDownload = false;
                    }
                );
            }, 5000);
        }

        $scope.addListExport = function (listId) {
            $scope.preparingDownload = true;
            var fields = [];
            if ($scope.showid) {
                fields.push('id');
            }
            fields.push('text');
            if ($scope.trans_lang != 'none') {
                fields.push('trans_text');
            }
            $http.post(rootUrl + "/exports/add", {
                     'type': 'list',
                     'list_id': listId,
                     'fields': fields,
                     'trans_lang': $scope.trans_lang,
                 })
                 .then(
                    function(response) {
                        $scope.export = response.data.export;
                        $scope.tryToDownloadList();
                    },
                    function(errorResponse) {
                        $scope.preparingDownload = false;
                    }
                 );
        };
    }]);
})();
<|endoftext|>


<commit_before>Application.Controllers.controller('_indexNavigation',
                                   ["$scope", "User", "$state", "current",
                                    _indexNavigation]);
function _indexNavigation($scope, User, $state, current) {
    $scope.goHome = function () {
        if (User.isAuthenticated()) {
            $state.go("projects.project.home", {id: current.projectID()});
        } else {
            $state.go("home");
        }
    };
}
<commit_msg>navigation index<commit_after>Application.Controllers.controller('_indexNavigation',
                                   ["$scope", "User", "$state", "current",
                                    _indexNavigation]);
function _indexNavigation($scope, User, $state, current, $stateParams) {
    $scope.goHome = function () {
        if (User.isAuthenticated()) {
            $state.go("projects.project.home", {id: current.projectID()});
        } else {
            $state.go("home");
        }
    };
}
<|endoftext|>


<commit_before>/* eslint-disable react/forbid-prop-types */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import React from 'react';
import PropTypes from 'prop-types';

import { Keyboard, StyleSheet, View } from 'react-native';
import Modal from 'react-native-modalbox';

import { DARKER_GREY } from '../../globalStyles/index';

export const BottomModalContainer = ({
  children,
  isOpen,
  swipeToClose,
  backdropPressToClose,
  position,
  backdrop,
  modalStyle,
  containerStyle,
  ...modalProps
}) => {
  React.useEffect(() => {
    Keyboard.dismiss();
  }, [isOpen]);

  return (
    <Modal
      swipeToClose={swipeToClose}
      backdropPressToClose={backdropPressToClose}
      position={position}
      backdrop={backdrop}
      {...modalProps}
      style={localStyles.modalStyle}
    >
      <View style={localStyles.containerStyle}>{children}</View>
    </Modal>
  );
};

const localStyles = StyleSheet.create({
  containerStyle: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  modalStyle: {
    height: 60,
    justifyContent: 'center',
    alignItems: 'flex-end',
    backgroundColor: DARKER_GREY,
  },
});

BottomModalContainer.defaultProps = {
  swipeToClose: false,
  backdropPressToClose: false,
  position: 'bottom',
  backdrop: false,
  modalStyle: localStyles.modalStyle,
  containerStyle: localStyles.containerStyle,
};

BottomModalContainer.propTypes = {
  isOpen: PropTypes.bool.isRequired,
  swipeToClose: PropTypes.bool,
  backdropPressToClose: PropTypes.bool,
  position: PropTypes.string,
  backdrop: PropTypes.bool,
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired,
  modalStyle: PropTypes.object,
  containerStyle: PropTypes.object,
};
<commit_msg>Add corrected prop usage in BottomModalContainer<commit_after>/* eslint-disable react/forbid-prop-types */
/**
 * mSupply Mobile
 * Sustainable Solutions (NZ) Ltd. 2019
 */

import React from 'react';
import PropTypes from 'prop-types';

import { Keyboard, StyleSheet, View } from 'react-native';
import Modal from 'react-native-modalbox';

import { DARKER_GREY } from '../../globalStyles/index';

export const BottomModalContainer = ({
  children,
  isOpen,
  swipeToClose,
  backdropPressToClose,
  position,
  backdrop,
  modalStyle,
  containerStyle,
  ...modalProps
}) => {
  React.useEffect(() => {
    Keyboard.dismiss();
  }, [isOpen]);

  return (
    <Modal
      swipeToClose={swipeToClose}
      backdropPressToClose={backdropPressToClose}
      position={position}
      backdrop={backdrop}
      isOpen={isOpen}
      {...modalProps}
      style={localStyles.modalStyle}
    >
      <View style={localStyles.containerStyle}>{children}</View>
    </Modal>
  );
};

const localStyles = StyleSheet.create({
  containerStyle: {
    flexDirection: 'row',
    flexWrap: 'wrap',
    justifyContent: 'flex-end',
    alignItems: 'center',
  },
  modalStyle: {
    height: 60,
    justifyContent: 'center',
    alignItems: 'flex-end',
    backgroundColor: DARKER_GREY,
  },
});

BottomModalContainer.defaultProps = {
  swipeToClose: false,
  backdropPressToClose: false,
  position: 'bottom',
  backdrop: false,
  modalStyle: localStyles.modalStyle,
  containerStyle: localStyles.containerStyle,
};

BottomModalContainer.propTypes = {
  isOpen: PropTypes.bool.isRequired,
  swipeToClose: PropTypes.bool,
  backdropPressToClose: PropTypes.bool,
  position: PropTypes.string,
  backdrop: PropTypes.bool,
  children: PropTypes.oneOfType([PropTypes.node, PropTypes.arrayOf(PropTypes.node)]).isRequired,
  modalStyle: PropTypes.object,
  containerStyle: PropTypes.object,
};
<|endoftext|>


<commit_before>(function(){
    var app = angular.module('coala', ['ngSanitize','btford.markdown', 'ngRoute']);

    app.factory('Languages', function ($location) {
        langs = [{
            'name' : 'English',
            'code' : 'en'
        },
        {
            'name' : 'Bahasa',
            'code' : 'id'
        },
        {
            'name' : 'हिन्दी',
            'code' : 'hi'
        },
        {
            'name' : 'Romanian',
            'code' : 'ro'
        }];
        selected_language = JSON.parse(window.localStorage.getItem('lang')) || langs[0];
        return {
            setData: function (val) {
                angular.forEach(langs, function(v, k){
                    if (v.code == val){
                        window.localStorage.setItem('lang', JSON.stringify(v));
                        selected_language = v;
                    }
                });
            },
            getData: function () {
                return selected_language['code'];

            },
            getAllLanguages: function () {
                return langs;
            },
            getLanguageObject: function () {
                return selected_language;
            }
        }
    });

    app.config(['$routeProvider',
        function($routeProvider) {
            $routeProvider.
            when('/projects', {
                template: '<projects></projects>',
                reloadOnSearch: false
            }).
            when('/mentors', {
                template: '<mentors></mentors>'
            }).
            when('/faq', {
                template: '<faq></faq>'
            }).
            otherwise({
                redirectTo: '/projects'
            });
    }]);

    app.controller('LanguageController', function ($scope, Languages) {
        $scope.langs = Languages.getAllLanguages();
        $scope.update = function () {
            Languages.setData($scope.language.code);
        }
        $scope.init_language = Languages.getLanguageObject();
        $scope.getLanguage = function () {
            $scope.init_language = Languages.getLanguageObject();
            $(document).ready(function(){
                $('select').material_select();
            })
            $scope.$evalAsync();
            return $scope.init_language;
        }
    })

    app.controller('TabController', function ($location) {
        this.tab = $location.path()
        this.setTab = function (stab) {
            this.tab = stab
            $location.path(stab);
        }
        this.isSet = function (stab) {
            return $location.path() == stab
        }
    })

    app.directive('projects',  ['$http',  '$timeout', '$location', 'Languages', function ($http, $timeout, $location, Languages) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/projects.html',
            controller: function ($scope, $location, Languages) {
                self = this

                var mapping = {
                    '': 0,
                    'crowded': 1,
                    'in_progress': 2,
                    'completed': 3
                }

                $scope.sortOrder = function(project) {
                    return mapping[project.status];
                }

                $scope.getDefaultProjectsMetadata = function () {
                    $http.get('data/projects.liquid')
                        .then(function (res) {
                            $scope.projectList = res.data;
                            $scope.projectRequest();
                        })
                }

                $scope.lang = Languages.getData();

                $scope.getDefaultProjectsMetadata();

                $scope.$watch( function () {
                    return Languages.getData();
                }, function () {
                    $scope.setLanguage(Languages.getData());
                }, true);

                $scope.setLanguage = function (val) {
                    $scope.lang = val;
                    $scope.updateProjects();
                }

                $scope.updateProjects = function () {
                    if ($scope.lang != 'en') {
                        $http.get('data/locale/'+$scope.lang+'/projects.json')
                            .then(function (res) {
                                $scope.projectList.map(function (project) {
                                    if (res.data[project.markdown]) {
                                        Object.keys(project).map(function (key) {
                                            if (res.data[project.markdown][key]) {
                                                project[key] = res.data[project.markdown][key]
                                            }
                                        });
                                    }
                                });

                                $scope.projectRequest();
                            });
                    } else {
                        $scope.getDefaultProjectsMetadata();
                        $scope.projectRequest();
                    }
                }

                function generateMarkdown() {

                    function setFromDefault() {
                        $http.get($scope.currentProject.content_url)
                            .then(function (res) {
                                $scope.currentProject.content = res.data
                            }, function() {
                                $scope.currentProject.content = 'No content'
                            });
                    }

                    if ($scope.lang != 'en') {
                        $http.get('data/locale/' + $scope.lang + '/projects/' + $scope.currentProject.markdown).then(function (res) {
                            $scope.currentProject.content = res.data
                        }, function () {
                            setFromDefault()
                        });
                    } else {
                        setFromDefault()
                    }
                }

                self.showProject = function (project) {

                    $scope.currentProject = project

                    $(document).ready(function () {
                        $('.modal').modal('open');
                    });

                    mval = encodeURIComponent(project["name"].split(' ').join('_').toLowerCase());
                    $location.url('?project=' + mval + ( $scope.lang ? '&lang=' + $scope.lang : '' ))
                    $scope.$evalAsync();

                    generateMarkdown()
                }

                self.showProjectOnArrowClick = function (project) {

                    $scope.currentProject = project
                    mval = encodeURIComponent(project["name"].split(' ').join('_').toLowerCase());
                    $location.url('?project=' + mval + ( $scope.lang ? '&lang=' + $scope.lang : '' ))
                                        $scope.$evalAsync();
                    generateMarkdown()
                }

                $scope.search = function (arg) {
                    $scope.searchText = arg
                }

                $scope.redirect = function (arg) {
                    window.open(arg, '_blank');
                }

                $scope.updateLink = function () {
                    $scope.currentProject = null;
                    $location.url($location.path());
                }

                $scope.encode_URI = function (project_name) {
                    return encodeURIComponent(project_name.split(' ').join('_').toLowerCase());
                }

                $scope.arrowPressed = function (e) {
                    if(e.keyCode == 37){
                        keyPressed = "left"
                                    $scope.moveToNext(keyPressed);
                    }
                    else if(e.keyCode == 39){
                        keyPressed = "right"
                                    $scope.moveToNext(keyPressed);
                    }

                }

                $scope.moveToNext = function (keyPressed) {
                    if($scope.currentProject){

                        total_projects = $scope.projectList.length
                        angular.forEach($scope.projectList, function(value, key){
                            if($scope.currentProject.name == value["name"]){
                                current_project_index = key
                            }
                        });

                        if(keyPressed == "left"){
                            if(current_project_index == 0){
                                self.showProjectOnArrowClick($scope.projectList[total_projects-1])
                            }else{
                                self.showProjectOnArrowClick($scope.projectList[--current_project_index])
                            }
                        }
                        if(keyPressed == "right"){
                            if(current_project_index == total_projects-1){
                                self.showProjectOnArrowClick($scope.projectList[0])
                            }else{
                                self.showProjectOnArrowClick($scope.projectList[++current_project_index])
                            }
                        }
                    }
                }

                $scope.projectRequest = function () {
                    $scope.projects_url_dict = {}
                    $scope.projects_url_list = Object.keys($scope.projects_url_dict);
                    angular.forEach($scope.projectList, function(value, key){
                        value["url"] = encodeURIComponent(value["name"].split(' ').join('_').toLowerCase());
                        $scope.projects_url_dict[value["url"]] = key
                    });

                    var project_requested = encodeURIComponent($location.search().project);
                    if(project_requested){
                        if(Object.keys($scope.projects_url_dict).indexOf(project_requested) > -1){
                            self.showProject($scope.projectList[$scope.projects_url_dict[project_requested]])
                        }
                    }
                }

                var search_requested = $location.search().q;
                if(search_requested){
                    $scope.searchText = search_requested
                }

            },
            controllerAs: 'lc'
        }
    }]);

    app.directive('faq',[ '$http', '$templateCache', function ($http, $templateCache, Languages) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/faq.html',
            controller: function ($scope, Languages) {
                $scope.lang = Languages.getData();

                $scope.getDefaultFAQMetadata = function () {
                    $http.get('data/faq.liquid')
                        .then(function (res) {
                            $scope.faqs = res.data;
                            $scope.generateMarkdown();
                        })
                }

                $scope.lang = Languages.getData();

                $scope.getDefaultFAQMetadata();

                $scope.$watch( function () {
                    return Languages.getData();
                }, function () {
                    $scope.setLanguage(Languages.getData());
                }, true);

                $scope.setLanguage = function (val) {
                    $scope.lang = val;
                    $scope.updateFAQ();
                }

                $scope.updateFAQ = function () {
                    if ($scope.lang != 'en') {

                        $http.get('data/locale/'+$scope.lang+'/faq.json')
                            .then(function (res) {
                                $scope.faqs.map(function (faq) {
                                    if (res.data[faq.markdown]) {
                                        Object.keys(faq).map(function (key) {
                                            if (res.data[faq.markdown]) {
                                                faq['question'] = res.data[faq.markdown]

                                            }
                                        });
                                    }
                                });
                                $scope.generateMarkdown();
                            });
                    } else {
                        $scope.getDefaultFAQMetadata();
                    }
                }

                $scope.generateMarkdown = function() {

                    if ($scope.lang != 'en') {
                        $scope.faqs.forEach(function (faq, key) {
                            $http.get('data/locale/' + $scope.lang + '/faq/' + faq.markdown)
                                .then(function (res) {
                                    $scope.faqs[key].answer = res.data
                                }, function (error) {
                                    $http.get($scope.faqs[key].url)
                                        .then(function (res) {
                                            $scope.faqs[key].answer = res.data;
                                        })
                                });
                        })
                    } else {
                        $scope.faqs.forEach(function (f, k) {
                            $http.get($scope.faqs[k].url)
                                .then(function (res) {
                                    $scope.faqs[k].answer = res.data
                                });
                        })
                    }
                }

            },
            controllerAs: 'toc'
        }
    }]);

    app.filter('format_issue', function () {
        return function (value) {
            if (!value) return '';
            res = value.split('/');
            last = res.length - 1;
            return res.slice(3, last - 1).join('/') + '#' + res[last];
        };
    });

    app.directive('mentors', ['$http', function ($http) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/mentors.html',
            controller: function ($scope, $rootScope) {
                self = this
                self.mentorsList = {}
                self.adminsList = {}

                $http.get('data/projects.liquid')
                    .then(function (res) {
                        $scope.projects = res.data
                        angular.forEach($scope.projects, function(value, key){
                            angular.forEach(value.mentors, function(value, key){
                                self.mentorsList[value] =  {
                                    "github_handle" : value,
                                    "github_avatar_url": "https://avatars.githubusercontent.com/" +value
                                }
                            });
                        });
                    })

                $http.get('data/admins.json')
                    .then(function (res) {
                        admins = res.data
                        angular.forEach(admins, function(value, key){
                            self.adminsList[value] = {
                                "github_handle" : value,
                                "github_avatar_url": "https://avatars.githubusercontent.com/" +value

                            }
                        });
                    })

            },
            controllerAs: "gic"
        }
    }]);

})();
<commit_msg>app.js: Exclude mentors on completed projects<commit_after>(function(){
    var app = angular.module('coala', ['ngSanitize','btford.markdown', 'ngRoute']);

    app.factory('Languages', function ($location) {
        langs = [{
            'name' : 'English',
            'code' : 'en'
        },
        {
            'name' : 'Bahasa',
            'code' : 'id'
        },
        {
            'name' : 'हिन्दी',
            'code' : 'hi'
        },
        {
            'name' : 'Romanian',
            'code' : 'ro'
        }];
        selected_language = JSON.parse(window.localStorage.getItem('lang')) || langs[0];
        return {
            setData: function (val) {
                angular.forEach(langs, function(v, k){
                    if (v.code == val){
                        window.localStorage.setItem('lang', JSON.stringify(v));
                        selected_language = v;
                    }
                });
            },
            getData: function () {
                return selected_language['code'];

            },
            getAllLanguages: function () {
                return langs;
            },
            getLanguageObject: function () {
                return selected_language;
            }
        }
    });

    app.config(['$routeProvider',
        function($routeProvider) {
            $routeProvider.
            when('/projects', {
                template: '<projects></projects>',
                reloadOnSearch: false
            }).
            when('/mentors', {
                template: '<mentors></mentors>'
            }).
            when('/faq', {
                template: '<faq></faq>'
            }).
            otherwise({
                redirectTo: '/projects'
            });
    }]);

    app.controller('LanguageController', function ($scope, Languages) {
        $scope.langs = Languages.getAllLanguages();
        $scope.update = function () {
            Languages.setData($scope.language.code);
        }
        $scope.init_language = Languages.getLanguageObject();
        $scope.getLanguage = function () {
            $scope.init_language = Languages.getLanguageObject();
            $(document).ready(function(){
                $('select').material_select();
            })
            $scope.$evalAsync();
            return $scope.init_language;
        }
    })

    app.controller('TabController', function ($location) {
        this.tab = $location.path()
        this.setTab = function (stab) {
            this.tab = stab
            $location.path(stab);
        }
        this.isSet = function (stab) {
            return $location.path() == stab
        }
    })

    app.directive('projects',  ['$http',  '$timeout', '$location', 'Languages', function ($http, $timeout, $location, Languages) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/projects.html',
            controller: function ($scope, $location, Languages) {
                self = this

                var mapping = {
                    '': 0,
                    'crowded': 1,
                    'in_progress': 2,
                    'completed': 3
                }

                $scope.sortOrder = function(project) {
                    return mapping[project.status];
                }

                $scope.getDefaultProjectsMetadata = function () {
                    $http.get('data/projects.liquid')
                        .then(function (res) {
                            $scope.projectList = res.data;
                            $scope.projectRequest();
                        })
                }

                $scope.lang = Languages.getData();

                $scope.getDefaultProjectsMetadata();

                $scope.$watch( function () {
                    return Languages.getData();
                }, function () {
                    $scope.setLanguage(Languages.getData());
                }, true);

                $scope.setLanguage = function (val) {
                    $scope.lang = val;
                    $scope.updateProjects();
                }

                $scope.updateProjects = function () {
                    if ($scope.lang != 'en') {
                        $http.get('data/locale/'+$scope.lang+'/projects.json')
                            .then(function (res) {
                                $scope.projectList.map(function (project) {
                                    if (res.data[project.markdown]) {
                                        Object.keys(project).map(function (key) {
                                            if (res.data[project.markdown][key]) {
                                                project[key] = res.data[project.markdown][key]
                                            }
                                        });
                                    }
                                });

                                $scope.projectRequest();
                            });
                    } else {
                        $scope.getDefaultProjectsMetadata();
                        $scope.projectRequest();
                    }
                }

                function generateMarkdown() {

                    function setFromDefault() {
                        $http.get($scope.currentProject.content_url)
                            .then(function (res) {
                                $scope.currentProject.content = res.data
                            }, function() {
                                $scope.currentProject.content = 'No content'
                            });
                    }

                    if ($scope.lang != 'en') {
                        $http.get('data/locale/' + $scope.lang + '/projects/' + $scope.currentProject.markdown).then(function (res) {
                            $scope.currentProject.content = res.data
                        }, function () {
                            setFromDefault()
                        });
                    } else {
                        setFromDefault()
                    }
                }

                self.showProject = function (project) {

                    $scope.currentProject = project

                    $(document).ready(function () {
                        $('.modal').modal('open');
                    });

                    mval = encodeURIComponent(project["name"].split(' ').join('_').toLowerCase());
                    $location.url('?project=' + mval + ( $scope.lang ? '&lang=' + $scope.lang : '' ))
                    $scope.$evalAsync();

                    generateMarkdown()
                }

                self.showProjectOnArrowClick = function (project) {

                    $scope.currentProject = project
                    mval = encodeURIComponent(project["name"].split(' ').join('_').toLowerCase());
                    $location.url('?project=' + mval + ( $scope.lang ? '&lang=' + $scope.lang : '' ))
                                        $scope.$evalAsync();
                    generateMarkdown()
                }

                $scope.search = function (arg) {
                    $scope.searchText = arg
                }

                $scope.redirect = function (arg) {
                    window.open(arg, '_blank');
                }

                $scope.updateLink = function () {
                    $scope.currentProject = null;
                    $location.url($location.path());
                }

                $scope.encode_URI = function (project_name) {
                    return encodeURIComponent(project_name.split(' ').join('_').toLowerCase());
                }

                $scope.arrowPressed = function (e) {
                    if(e.keyCode == 37){
                        keyPressed = "left"
                                    $scope.moveToNext(keyPressed);
                    }
                    else if(e.keyCode == 39){
                        keyPressed = "right"
                                    $scope.moveToNext(keyPressed);
                    }

                }

                $scope.moveToNext = function (keyPressed) {
                    if($scope.currentProject){

                        total_projects = $scope.projectList.length
                        angular.forEach($scope.projectList, function(value, key){
                            if($scope.currentProject.name == value["name"]){
                                current_project_index = key
                            }
                        });

                        if(keyPressed == "left"){
                            if(current_project_index == 0){
                                self.showProjectOnArrowClick($scope.projectList[total_projects-1])
                            }else{
                                self.showProjectOnArrowClick($scope.projectList[--current_project_index])
                            }
                        }
                        if(keyPressed == "right"){
                            if(current_project_index == total_projects-1){
                                self.showProjectOnArrowClick($scope.projectList[0])
                            }else{
                                self.showProjectOnArrowClick($scope.projectList[++current_project_index])
                            }
                        }
                    }
                }

                $scope.projectRequest = function () {
                    $scope.projects_url_dict = {}
                    $scope.projects_url_list = Object.keys($scope.projects_url_dict);
                    angular.forEach($scope.projectList, function(value, key){
                        value["url"] = encodeURIComponent(value["name"].split(' ').join('_').toLowerCase());
                        $scope.projects_url_dict[value["url"]] = key
                    });

                    var project_requested = encodeURIComponent($location.search().project);
                    if(project_requested){
                        if(Object.keys($scope.projects_url_dict).indexOf(project_requested) > -1){
                            self.showProject($scope.projectList[$scope.projects_url_dict[project_requested]])
                        }
                    }
                }

                var search_requested = $location.search().q;
                if(search_requested){
                    $scope.searchText = search_requested
                }

            },
            controllerAs: 'lc'
        }
    }]);

    app.directive('faq',[ '$http', '$templateCache', function ($http, $templateCache, Languages) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/faq.html',
            controller: function ($scope, Languages) {
                $scope.lang = Languages.getData();

                $scope.getDefaultFAQMetadata = function () {
                    $http.get('data/faq.liquid')
                        .then(function (res) {
                            $scope.faqs = res.data;
                            $scope.generateMarkdown();
                        })
                }

                $scope.lang = Languages.getData();

                $scope.getDefaultFAQMetadata();

                $scope.$watch( function () {
                    return Languages.getData();
                }, function () {
                    $scope.setLanguage(Languages.getData());
                }, true);

                $scope.setLanguage = function (val) {
                    $scope.lang = val;
                    $scope.updateFAQ();
                }

                $scope.updateFAQ = function () {
                    if ($scope.lang != 'en') {

                        $http.get('data/locale/'+$scope.lang+'/faq.json')
                            .then(function (res) {
                                $scope.faqs.map(function (faq) {
                                    if (res.data[faq.markdown]) {
                                        Object.keys(faq).map(function (key) {
                                            if (res.data[faq.markdown]) {
                                                faq['question'] = res.data[faq.markdown]

                                            }
                                        });
                                    }
                                });
                                $scope.generateMarkdown();
                            });
                    } else {
                        $scope.getDefaultFAQMetadata();
                    }
                }

                $scope.generateMarkdown = function() {

                    if ($scope.lang != 'en') {
                        $scope.faqs.forEach(function (faq, key) {
                            $http.get('data/locale/' + $scope.lang + '/faq/' + faq.markdown)
                                .then(function (res) {
                                    $scope.faqs[key].answer = res.data
                                }, function (error) {
                                    $http.get($scope.faqs[key].url)
                                        .then(function (res) {
                                            $scope.faqs[key].answer = res.data;
                                        })
                                });
                        })
                    } else {
                        $scope.faqs.forEach(function (f, k) {
                            $http.get($scope.faqs[k].url)
                                .then(function (res) {
                                    $scope.faqs[k].answer = res.data
                                });
                        })
                    }
                }

            },
            controllerAs: 'toc'
        }
    }]);

    app.filter('format_issue', function () {
        return function (value) {
            if (!value) return '';
            res = value.split('/');
            last = res.length - 1;
            return res.slice(3, last - 1).join('/') + '#' + res[last];
        };
    });

    app.directive('mentors', ['$http', function ($http) {
        return {
            restrict: 'E',
            templateUrl: '/partials/tabs/mentors.html',
            controller: function ($scope, $rootScope) {
                self = this
                self.mentorsList = {}
                self.adminsList = {}

                $http.get('data/projects.liquid')
                    .then(function (res) {
                        $scope.projects = res.data.filter(project => project.status != "completed")
                        angular.forEach($scope.projects, function(value, key){
                            angular.forEach(value.mentors, function(value, key){
                                self.mentorsList[value] =  {
                                    "github_handle" : value,
                                    "github_avatar_url": "https://avatars.githubusercontent.com/" +value
                                }
                            });
                        });
                    })

                $http.get('data/admins.json')
                    .then(function (res) {
                        admins = res.data
                        angular.forEach(admins, function(value, key){
                            self.adminsList[value] = {
                                "github_handle" : value,
                                "github_avatar_url": "https://avatars.githubusercontent.com/" +value

                            }
                        });
                    })

            },
            controllerAs: "gic"
        }
    }]);

})();
<|endoftext|>


<commit_before>var Future = Npm.require("fibers/future");

reddcoin = function(object) {
    this.rdd = Npm.require("node-reddcoin")(object);
};

// reddcoind getbalance [account]
reddcoin.prototype.balance = function(account) {
    var future = new Future();

    if(account) {
        this.rdd.exec("getbalance", account, function(err, balance) {
            if(err) {
                console.log(err);
                future.return(err);
            } else {
                future.return(balance);
            }
        });
    } else {
        this.rdd.exec("getbalance", function(err, balance) {
            if(err) {
                console.log(err);
                future.return(err);
            } else {
                future.return(balance);
            }
        });
    }

    return future.wait();
};

// reddcoind getinfo
reddcoin.prototype.info = function() {
    var future = new Future();

    this.rdd.exec("getinfo", function(err, info) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(info);
        }
    });

    return future.wait();
}

// reddcoind gettransaction txid
reddcoin.prototype.transaction = function(txid) {
    var future = new Future();

    this.rdd.exec("gettransaction", txid, function(err, transaction) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(transaction);
        }
    });

    return future.wait();
};

// reddcoind listtransactions
reddcoin.prototype.transactions = function() {
    var future = new Future();

    this.rdd.exec("listtransactions", function(err, transactions) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(transactions);
        }
    });

    return future.wait();
};

// reddcoind listaccounts
reddcoin.prototype.accounts = function() {
    var future = new Future();

    this.rdd.exec("listaccounts", function(err, accounts) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(accounts);
        }
    });

    return future.wait();
};

// reddcoind validateaddress address
reddcoin.prototype.validate = function(address) {
    var future = new Future();

    this.rdd.exec("validateaddress", address, function(err, validate) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(validate);
        }
    });

    return future.wait();
};

// reddcoind getstakinginfo
reddcoin.prototype.stake = function() {
    var future = new Future();

    this.rdd.exec("getstakinginfo", function(err, stake) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(stake);
        }
    });

    return future.wait();
};

// reddcoind walletpassphrase passphrase timeout stakeonly?
reddcoin.prototype.unlock = function(passphrase, timeout, stakeonly) {
    var future = new Future();

    if(stakeonly == undefined) {
        stakeonly = false;
    }

    this.rdd.exec("walletpassphrase", passphrase, timeout, stakeonly, function(err, unlock) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(unlock);
        }
    });

    return future.wait();
};

// reddcoind walletlock
reddcoin.prototype.lock = function() {
    var future = new Future();

    this.rdd.exec("walletlock", function(err, lock) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(lock);
        }
    });

    return future.wait();
};

// reddcoind send to_address amount [comment]
reddcoin.prototype.send = function(address, amount, comment) {
    var future = new Future();

    this.rdd.exec("send", address, amount, comment, function(err, send) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(send);
        }
    });

    return future.wait();
}

// reddcoind getblockcount
reddcoin.prototype.blockcount = function() {
    var future = new Future();

    this.rdd.exec("getblockcount", function(err, blockcount) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(blockcount);
        }
    });

    return future.wait();
}

// reddcoind getblockhash [index]
reddcoin.prototype.blockhash = function(index) {
    var future = new Future();

    this.rdd.exec("getblockhash", index, function(err, hash) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(hash);
        }
    });

    return future.wait();
}

// reddcoind getblock [hash]
reddcoin.prototype.block = function(hash) {
    var future = new Future();

    this.rdd.exec("getblock", hash, function(err, block) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(block);
        }
    });

    return future.wait();
}<commit_msg>fix send command<commit_after>var Future = Npm.require("fibers/future");

reddcoin = function(object) {
    this.rdd = Npm.require("node-reddcoin")(object);
};

// reddcoind getbalance [account]
reddcoin.prototype.balance = function(account) {
    var future = new Future();

    if(account) {
        this.rdd.exec("getbalance", account, function(err, balance) {
            if(err) {
                console.log(err);
                future.return(err);
            } else {
                future.return(balance);
            }
        });
    } else {
        this.rdd.exec("getbalance", function(err, balance) {
            if(err) {
                console.log(err);
                future.return(err);
            } else {
                future.return(balance);
            }
        });
    }

    return future.wait();
};

// reddcoind getinfo
reddcoin.prototype.info = function() {
    var future = new Future();

    this.rdd.exec("getinfo", function(err, info) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(info);
        }
    });

    return future.wait();
}

// reddcoind gettransaction txid
reddcoin.prototype.transaction = function(txid) {
    var future = new Future();

    this.rdd.exec("gettransaction", txid, function(err, transaction) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(transaction);
        }
    });

    return future.wait();
};

// reddcoind listtransactions
reddcoin.prototype.transactions = function() {
    var future = new Future();

    this.rdd.exec("listtransactions", function(err, transactions) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(transactions);
        }
    });

    return future.wait();
};

// reddcoind listaccounts
reddcoin.prototype.accounts = function() {
    var future = new Future();

    this.rdd.exec("listaccounts", function(err, accounts) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(accounts);
        }
    });

    return future.wait();
};

// reddcoind validateaddress address
reddcoin.prototype.validate = function(address) {
    var future = new Future();

    this.rdd.exec("validateaddress", address, function(err, validate) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(validate);
        }
    });

    return future.wait();
};

// reddcoind getstakinginfo
reddcoin.prototype.stake = function() {
    var future = new Future();

    this.rdd.exec("getstakinginfo", function(err, stake) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(stake);
        }
    });

    return future.wait();
};

// reddcoind walletpassphrase passphrase timeout stakeonly?
reddcoin.prototype.unlock = function(passphrase, timeout, stakeonly) {
    var future = new Future();

    if(stakeonly == undefined) {
        stakeonly = false;
    }

    this.rdd.exec("walletpassphrase", passphrase, timeout, stakeonly, function(err, unlock) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(unlock);
        }
    });

    return future.wait();
};

// reddcoind walletlock
reddcoin.prototype.lock = function() {
    var future = new Future();

    this.rdd.exec("walletlock", function(err, lock) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(lock);
        }
    });

    return future.wait();
};

// reddcoind sendtoaddress to_address amount [comment]
reddcoin.prototype.send = function(address, amount, comment) {
    var future = new Future();

    this.rdd.exec("sendtoaddress", address, amount, comment, function(err, send) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(send);
        }
    });

    return future.wait();
}

// reddcoind getblockcount
reddcoin.prototype.blockcount = function() {
    var future = new Future();

    this.rdd.exec("getblockcount", function(err, blockcount) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(blockcount);
        }
    });

    return future.wait();
}

// reddcoind getblockhash [index]
reddcoin.prototype.blockhash = function(index) {
    var future = new Future();

    this.rdd.exec("getblockhash", index, function(err, hash) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(hash);
        }
    });

    return future.wait();
}

// reddcoind getblock [hash]
reddcoin.prototype.block = function(hash) {
    var future = new Future();

    this.rdd.exec("getblock", hash, function(err, block) {
        if(err) {
            console.log(err);
            future.return(err);
        } else {
            future.return(block);
        }
    });

    return future.wait();
}
<|endoftext|>


<commit_before>const date = {
 isostring: `takes one argument: value
             Returns a string in simplified extended ISO format.`,

 format: `Takes two arguments: date, format
          Parses date to the passed format.
          A date argument could be a Date object or a valid string date.
          When passed date is invalid, method returns "Invalid Date" message.
          By default date is parsed to the YYYY-MM-DD format.
          Is possible to parse date only to the month, day, etc. format.`,

  day: `Takes one argument: date
        Returns the day of the month (from 1 to 31) for the passed date.`,

  month: `Takes one argument: date
          Returns the month from (0 to 11) for the passed date.`,

  year: `Takes one argument: date
         Returns the year (four digits for dates between year 1000 and 9999) for the passed date.`,

  weekday: `Takes one argument: date
            Returns the day of the week from (0 to 6) for the specified date.`,

  prettydate: `Takes two arguments: date, localization
               Returns a string, that contains: the name of weekday, day of the month (from 1 to 31), name of the month, and year (four digits for dates between year 1000 and 9999).
               Example output for 'en-En' localization: Wednesday, 21st of March 2018.
               localization can be 'en-En' or 'pl-Pl', in other case function throws error.
               By default localization equals 'en-En'.`
}

module.exports = date
<commit_msg>Added polish translations for date.js<commit_after>const date = [
  isostring: {
    parameters: ['value']
    description: {
      en: 'Returns a string in simplified extended ISO format.',
      pl: 'Zwraca łańuch znaków w uproszczonym rozszerzonym formacie ISO.'
    }
  }
 format: {
  parameters: ['date', 'format']
  description: {
    en: 'Parses date to the passed format. A date argument could be a Date object or a valid string date. When passed date is invalid, method returns "Invalid Date" message. By default date is parsed to the YYYY-MM-DD format. Is possible to parse date only to the month, day, etc. format.',
    pl: 'Parsuje datę na format przekazany do funkcji. Parametr "date" może być obiektem typu Date lub łańcuchem znaków, z którego można utworzyć datę. W prypadku, gdy do funkcji, zostnaie przekazana nieprawidłowa data, funkcja zwróci błąd "Invalid Date". Domyślnym formatem jest: "YYYY-MM-DD".'
  }
 }
  day: {
    parameters: ['date']
    description: {
      en: 'Returns the day of the month (from 1 to 31) for the passed date.',
      pl: 'Zwraca dzień miesiąca (od 1 do 31), na podstawie przekazanej daty.',
    }
  }
  month: {
    parameters: ['date'],
    description: {
      en: 'Returns the month from (0 to 11) for the passed date.',
      pl: 'Zwraca miesiąc (od 0 do 11), na podstawie przekazanej daty.'
    }
  }
  year: {
    parameters: ['date'],
    description: {
      en: 'Returns the year (four digits for dates between year 1000 and 9999) for the passed date.',
      pl: 'Zwraca rok, na podstawie przekazanej daty.'
  },
  weekday: {
    parameters: ['date'],
    description: {
      en: 'Returns the day of the week (from 0 to 6) for the specified date.',
      pl: 'Zwraca dzień tygodnia (od 0 do 6) na podstawie przekazanej daty.'
    }
  },
  prettydate: {
    parameters: ['date', 'localization'],
    description: {
      en: `Returns a string, that contains: the name of weekday, day of the month (from 1 to 31), name of the month, and year (four digits for dates between year 1000 and 9999).
           localization can be 'en-En' or 'pl-Pl', in other case function throws error.
           By default localization equals 'en-En'.`,
      pl: `Zwraca łańuch znaków, który zawiera: nazwę dnia tygodnia, dzień miesiąca (od 1 do 31), nazwę miesiąca oraz rok.
           Parametr "localization" może przyjąć wartość 'en-En' lub 'pl-Pl', w innym przypadku funkcja zwróci błąd.
           Domyślnie parametr 'localization' przyjmuje wartość 'en-En' i zwraca łańuch znaków w języku angielskim.`
    }
  }
]
module.exports = date
<|endoftext|>


<commit_before>testss<commit_msg>Delete core.js<commit_after><|endoftext|>