GoalModelEditor/FrontEnd/public/js/projectEdit/graphXML.js
/**
 * Can only be called when the svg is rendered onto the screen!!!!!!
 */
Can only be called when the svg is rendered onto the screen
Can only be called when the svg is rendered onto the screen
function exportModel() {
    recentreView();
    let secret = JSON.parse(Cookies.get("LOKIDIED"));
    let token = secret.token;
    let userId = secret.uid;
    let modelId = Cookies.get("MID");
    let export_url = "/goal_model/exportToPng/" + userId + "/" + modelId;
    let svg = document.getElementsByTagName("svg")[0];
    svg.setAttribute("xmlns", "http://www.w3.org/2000/svg");
    svg.setAttribute("version", "1.1");
    svg.setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");
    let style = svg.getAttribute("style").split(";")
    let width = style[3].split(":")[1];
    let height = style[4].split(":")[1];
    svg.setAttribute("width", width);
    svg.setAttribute("height", height);
    let serializer = new XMLSerializer();
    let ser = serializer.serializeToString(svg);
    $.ajax(export_url, {
        type: "POST",
        headers: {Authorization: "Bearer " + token},
        contentType: "application/json",
        data: JSON.stringify({svg: ser}),
        success: function (res) {
            console.log(res.png.data);
            let data = new Uint8Array(res.png.data);
            let pngFile = new Blob([data], {type: "image/png"});
            console.log(pngFile);
            if (window.navigator.msSaveOrOpenBlob) 
            {
                window.navigator.msSaveOrOpenBlob(pngFile, Filename);
            } else { 
                let a = document.createElement("a"),
                    url = URL.createObjectURL(pngFile);
                a.href = url;
                a.download = "model.png";
                document.body.appendChild(a);
                a.click();
                setTimeout(function () {
                    document.body.removeChild(a);
                    window.URL.revokeObjectURL(url);
                }, 0);
            }
        }
    }).fail(function (jqXHR) {
        warningMessageSlide(
            jqXHR.responseJSON.message + "<br>Please try again."
        );
    });
}
function exportModel ( ) { recentreView ( ) ; let secret = JSON . parse ( Cookies . get ( "LOKIDIED" ) ) ; let token = secret . token ; let userId = secret . uid ; let modelId = Cookies . get ( "MID" ) ; let export_url = "/goal_model/exportToPng/" + userId + "/" + modelId ; let svg = document . getElementsByTagName ( "svg" ) [ 0 ] ; svg . setAttribute ( "xmlns" , "http://www.w3.org/2000/svg" ) ; svg . setAttribute ( "version" , "1.1" ) ; svg . setAttribute ( "xmlns:xlink" , "http://www.w3.org/1999/xlink" ) ; let style = svg . getAttribute ( "style" ) . split ( ";" ) let width = style [ 3 ] . split ( ":" ) [ 1 ] ; let height = style [ 4 ] . split ( ":" ) [ 1 ] ; svg . setAttribute ( "width" , width ) ; svg . setAttribute ( "height" , height ) ; let serializer = new XMLSerializer ( ) ; let ser = serializer . serializeToString ( svg ) ; $ . ajax ( export_url , { type : "POST" , headers : { Authorization : "Bearer " + token } , contentType : "application/json" , data : JSON . stringify ( { svg : ser } ) , success : function ( res ) { console . log ( res . png . data ) ; let data = new Uint8Array ( res . png . data ) ; let pngFile = new Blob ( [ data ] , { type : "image/png" } ) ; console . log ( pngFile ) ; if ( window . navigator . msSaveOrOpenBlob ) { window . navigator . msSaveOrOpenBlob ( pngFile , Filename ) ; } else { let a = document . createElement ( "a" ) , url = URL . createObjectURL ( pngFile ) ; a . href = url ; a . download = "model.png" ; document . body . appendChild ( a ) ; a . click ( ) ; setTimeout ( function ( ) { document . body . removeChild ( a ) ; window . URL . revokeObjectURL ( url ) ; } , 0 ) ; } } } ) . fail ( function ( jqXHR ) { warningMessageSlide ( jqXHR . responseJSON . message + "<br>Please try again." ) ; } ) ; }
Can only be called when the svg is rendered onto the screen!!!!!
Can only be called when the svg is rendered onto the screen!!!!!
// IE10+ // Others