Announcement

Collapse
No announcement yet.

How to use VDP-Web autosave for not-admins

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to use VDP-Web autosave for not-admins

    I have a personal page within my campaign. On that page, I have a VDP-Document connected to a Meta database.

    Now I'm trying to use the plugin "VDP-Web Autosave". This is working, but only if I am Admin. If I try to use it without admin rights, I get the error: could not write data m (ERR:3080): Permission denied for writing data. Missing right: write. Click image for larger version

Name:	Knipsel.JPG
Views:	9
Size:	18.5 KB
ID:	360




    This is the code of the VDP-Web Autosave extension (I slightly modified the original):

    Code:
    //namespace
    edix = edix || {};
    
    // available prefixes / meta field types
    edix.extend = edix.extend || {};
      
    $(document).ready(function () {
        //Initialisieren der web api
        if (typeof edix.dsmxGetRootUrl === "undefined") {
            alert("Error: dsmx RootUrl helper function not found.");
        } else {
            if (dsmx.config.targetSystem == undefined || dsmx.config.targetSystem == null || dsmx.config.targetSystem.length == 0) {
                dsmx.config.targetSystem = window.location.host;
            }
            
            // VDP-Web Auto Save helper
            edix.vdpWebDirtySaveCount = 0;
            window.onbeforeunload = function () {
                //debugprint("On close edix.vdpWebDirtySaveCount=" + edix.vdpWebDirtySaveCount + "edix.vdpWebDirtySaveCount=" + edix.vdpWebDirtySaveCount + " in designer={{IsInDesigner}}");
    
                // Der Mechanismus darf nur nach dem ersten speichern aktiviert werden.
                if (edix.vdpWebDirtySaveCount > 0) {
                    if (typeof dsm != "undefined" && dsm && typeof dsm.vdpWeb != "undefined" && dsm.vdpWeb) {
                        if (edix.dsmxIsInDesigner() === false && dsm.vdpWeb.dirtyDocumentCount > 0 && edix.vdpWebDirtySaveCount != dsm.vdpWeb.dirtyDocumentCount) {
                            return "Are you sure you want to navigate away?";
                        } else {
    
                        };
                    };
                };
                // because of IE we don't return anything
               // return null;
            };
    
        }
    });
    
    /*********************************/
    /********* API HANDLING    *******/
    /*********************************/
    // For access from VD Web
    edix.storeValue = function (col, value) {
        // dont do it to often :-)
        var writing = false;
    
        var curValue = value;
        var curCol = col;
        var curTimeout = null;
     
        if (curCol.startsWith("Meta.") === false) return;
    
        if (writing) return;
        
        writing = true;
    
        // update nach 2 sekunden ...
        curTimeout = setTimeout(function () {
            
            //Updaten vorhandener datens├Ątze
            var table = dsmx.model.dataRelations.dataRelationTable.create();
            table.addColumn('xmediaID');//xmediaID bei internal database
            table.addColumn(curCol.substring(5));
    
            //Datens├Ątze festlegen
            var row = table.addRow();
            row[0] = 1;
            row[1] = curValue;
    
            console.log("update data ...");
    
            dsmx.api.dataRelations.update("Meta",
                table,
                function (result) {
                    // Success callback
                    if (result.state === 1) {
                        console.log("could not write data m (ERR:" + result.failureDetail + "): " + result.failureMessage);
                    } else {
                        // remeber last save for vdpWeb
                        if (col.indexOf("Meta.dml_") === 0) {
                            // increase VDP-Web dirty count + activate leave page check
                            edix.vdpWebDirtySaveCount = dsm.vdpWeb.dirtyDocumentCount;
                            // debugprint("save " + edix.vdpWebDirtySaveCount + " = " + dsm.vdpWeb.dirtyDocumentCount);
                        }
                    }
                    // 1 sec before next write
                    window.setTimeout(function () { writing = false; }, 1000);
                },
                function (e) {
                    // Failed callback
                    if (e.responseJSON && e.responseJSON.state == 1) {
                        console.log("could not write data mi (ERR:" + e.failureDetail + "): " + e.responseJSON.failureMessage);
                    } else {
                        console.log("could not write data: mit" + e.statusText);
                    }
                    // 1 sec before next write
                    window.setTimeout(function () { writing = false; }, 1000);
                }
            );
    
    
        }, 50);
    
    
    };
    How do I use this extension for not-admin users? is this even possible?
Working...
X