Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Saved model is obsolete error #309

Closed
jacekpl opened this issue Apr 8, 2017 · 3 comments
Closed

Saved model is obsolete error #309

jacekpl opened this issue Apr 8, 2017 · 3 comments

Comments

@jacekpl
Copy link

jacekpl commented Apr 8, 2017

Hi,

In know the other issue related to that one: #249.

I use the versafix-1 template (original one, without any changes). In this comment there is a hint to postfix variables with Visible. But which variables should I change?

Below my metadata:

{  
   "created":1491567997486,
   "key":"xpch3qy",
   "name":"versafix-1",
   "template":"/mosaico/templates/versafix-1/template-versafix-1.html",
   "editorversion":"0.16.0",
   "templateversion":"1.0.6",
   "changed":1491568026217
}

and content:

{  
   "type":"template",
   "customStyle":false,
   "preheaderVisible":true,
   "titleText":"TITLE",
   "preheaderBlock":{  
      "type":"preheaderBlock",
      "customStyle":false,
      "id":"ko_preheaderBlock_1",
      "backgroundColor":null,
      "preheaderText":"",
      "linkStyle":{  
         "type":"linkStyle",
         "face":null,
         "color":null,
         "size":null,
         "decoration":null
      },
      "preheaderLinkOption":"[unsubscribe_link]",
      "longTextStyle":{  
         "type":"longTextStyle",
         "face":null,
         "color":null,
         "size":null,
         "linksColor":null
      },
      "unsubscribeText":"Unsubscribe",
      "webversionText":"View in your browser"
   },
   "sponsor":{  
      "type":"sponsor",
      "visible":true,
      "src":"http://localhost:9006/templates/versafix-1/img/sponsor.gif",
      "url":"",
      "alt":"sponsor"
   },
   "footerBlock":{  
      "type":"footerBlock",
      "customStyle":false,
      "longTextStyle":{  
         "type":"longTextStyle",
         "face":null,
         "color":null,
         "size":null,
         "linksColor":null
      },
      "id":"ko_footerBlock_2",
      "backgroundColor":null,
      "linkStyle":{  
         "type":"linkStyle",
         "face":null,
         "color":null,
         "size":null,
         "decoration":null
      },
      "longText":"<p>Email sent to <a href=\"mailto:[mail]\">[mail]</a></p>",
      "disiscrivitiText":"Unsubscribe"
   },
   "mainBlocks":{  
      "type":"blocks",
      "blocks":[  

      ]
   },
   "theme":{  
      "type":"theme",
      "frameTheme":{  
         "type":"frameTheme",
         "backgroundColor":"#3f3f3f",
         "longTextStyle":{  
            "type":"longTextStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#919191",
            "size":"13",
            "linksColor":"#cccccc"
         },
         "linkStyle":{  
            "type":"linkStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#ffffff",
            "size":"13",
            "decoration":"underline"
         }
      },
      "contentTheme":{  
         "type":"contentTheme",
         "longTextStyle":{  
            "type":"longTextStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#3f3f3f",
            "size":"13",
            "linksColor":"#3f3f3f"
         },
         "externalBackgroundColor":"#bfbfbf",
         "externalTextStyle":{  
            "type":"textStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#f3f3f3",
            "size":"18"
         },
         "backgroundColor":"#ffffff",
         "titleTextStyle":{  
            "type":"textStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#3f3f3f",
            "size":"18"
         },
         "buttonStyle":{  
            "type":"buttonStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#3f3f3f",
            "size":"13",
            "buttonColor":"#bfbfbf",
            "radius":"4"
         },
         "bigTitleStyle":{  
            "type":"bigTitleStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#3f3f3f",
            "size":"22",
            "align":"center"
         },
         "hrStyle":{  
            "type":"hrStyle",
            "color":"#3f3f3f",
            "hrWidth":"100",
            "hrHeight":"1"
         },
         "bigButtonStyle":{  
            "type":"buttonStyle",
            "face":"Arial, Helvetica, sans-serif",
            "color":"#3f3f3f",
            "size":"22",
            "buttonColor":"#bfbfbf",
            "radius":"4"
         }
      }
   }
}

I use that plugin to save/load content. I would be grateful for any hints. Thanks.

@bago
Copy link
Member

bago commented Apr 8, 2017

#249 is about a customized template using a Boolean variable that is not named "*Visible". So, if you use an unchanged versafix-1 this can't be the same issue.

Please provide steps to reproduce, starting from a new template and provide full browser console output.

I tried to load your JSON on my versafix-1 and it loaded correctly without errors (it is an empty template).

@jacekpl
Copy link
Author

jacekpl commented Apr 8, 2017

This is js code I use:

<script>
        $(function() {
            localStorage.setItem("edits", '<?=$mosaico['edits']?>');
            localStorage.setItem("template-<?=$mosaico['edits']?>", '<?=$mosaico['template']?>');
            localStorage.setItem("metadata-<?=$mosaico['edits']?>", '<?=$mosaico['metadata']?>');

            if (!Mosaico.isCompatible()) {
                alert('Update your browser!');
                return;
            }
            // var basePath = window.location.href.substr(0, window.location.href.lastIndexOf('/')).substr(window.location.href.indexOf('/','https://'.length));
            var basePath = window.location.href;
            var processor_backend = basePath+'/dl/';
            if (basePath.lastIndexOf('#') > 0) basePath = basePath.substr(0, basePath.lastIndexOf('#'));
            if (basePath.lastIndexOf('?') > 0) basePath = basePath.substr(0, basePath.lastIndexOf('?'));
            if (basePath.lastIndexOf('/') > 0) basePath = basePath.substr(0, basePath.lastIndexOf('/'));
            // A basic plugin that expose the "viewModel" object as a global variable.
            // plugins = [function(vm) {window.viewModel = vm;}];
            var plugins = [
// plugin for integrating save button
                function(viewModel) {
                    var saveCmd = {
                        name: 'Save', // l10n happens in the template
                        enabled: ko.observable(true)
                    };

                    var downloadCmd = {
                        name: 'Download', // l10n happens in the template
                        enabled: ko.observable(true)
                    };

                    saveCmd.execute = function() {
                        saveCmd.enabled(false);
                        viewModel.metadata.changed = Date.now();
                        if(typeof viewModel.metadata.key == 'undefined') {
                            viewModel.metadata.key = Math.random().toString(36).substr(2, 7);
                        }

                        // This is the simplest for sending it as POST
                        // append postData with csrfToken
                        var postData = {
                            metadata: viewModel.exportMetadata(),
                            content: viewModel.exportJSON(),
                            html: viewModel.exportHTML()
                        };

                        $.post('/cms/emailTemplate/mosaicoUpdate', postData)
                            .done(function() {
                                viewModel.notifier.success(viewModel.t('Successfully saved.'));
                            })
                            .fail(function(jqXHR, textStatus, error) {
                                console.log(textStatus);
                                console.log(error);
                                console.log(jqXHR);
                                viewModel.notifier.error(viewModel.t('Saving failed. Please try again in a few moments or contact us.'));
                            })
                            .always(function() {
                                saveCmd.enabled(true);
                            });
                    };

                    downloadCmd.execute = function() {
                        downloadCmd.enabled(false);
                        viewModel.notifier.info(viewModel.t("Downloading..."));
                        viewModel.exportHTMLtoTextarea('#downloadHtmlTextarea');
                        var postUrl = basePath+'/dl/';
                        window.document.getElementById('downloadForm').setAttribute("action", postUrl);
                        window.document.getElementById('downloadForm').submit();
                        downloadCmd.enabled(true);
                    };

                    viewModel.save = saveCmd;
                    viewModel.download = downloadCmd;
                }
            ];

            var ok = Mosaico.start({
                    imgProcessorBackend: basePath+'/img/',
                    emailProcessorBackend: processor_backend,
                    titleToken: "MOSAICO Responsive Email Designer",
                    fileuploadConfig: {
                        url: basePath+'/upload/',
                        // messages??
                    }
                },
                '/mosaico/templates/versafix-1/template-versafix-1.html',
                <?=$mosaico['template']?>,
                <?=$mosaico['metadata']?>,
                plugins);
            if (!ok) {
                console.log("Missing initialization hash, redirecting to main entrypoint");
                //document.location = ".";
            }
        });
    </script>
$mosaico['edits'] = 'xpch3qy';

Screens from log
Log 1
Log 2

And exported log:

mosaico:112 Missing initialization hash, redirecting to main entrypoint
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
utils.js:61 Cannot apply default value to variable when using expressions
timed-call.js:25 translateTemplate: 670.232ms
timed-call.js:25 generateModel: 19.078ms
editor.js:138 TODO EDITOR ignoring longTextStyle.linksColor property because it is not used by the template prop: linksColor type: styler level: 2 preheaderBlock
editor.js:181 TODO WARN Missing label for object  theme
timed-call.js:25 generateEditors: 113.544ms
checkmodel.js:20 WARN Property  !R.editorversion found in model is not defined by template: removing it!
checkModel @ checkmodel.js:20
checkModel @ checkmodel.js:110
checkModel @ main.js:33
_call @ timed-call.js:13
_timedCall @ timed-call.js:16
templateCompiler @ template-loader.js:262
(anonymous) @ template-loader.js:167
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
checkmodel.js:20 WARN Property  !R.templateversion found in model is not defined by template: removing it!
checkModel @ checkmodel.js:20
checkModel @ checkmodel.js:110
checkModel @ main.js:33
_call @ timed-call.js:13
_timedCall @ timed-call.js:16
templateCompiler @ template-loader.js:262
(anonymous) @ template-loader.js:167
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
checkmodel.js:20 WARN Property  !R.changed found in model is not defined by template: removing it!
checkModel @ checkmodel.js:20
checkModel @ checkmodel.js:110
checkModel @ main.js:33
_call @ timed-call.js:13
_timedCall @ timed-call.js:16
templateCompiler @ template-loader.js:262
(anonymous) @ template-loader.js:167
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
checkmodel.js:20 WARN Property  !R.key found in model is not defined by template: removing it!
checkModel @ checkmodel.js:20
checkModel @ checkmodel.js:110
checkModel @ main.js:33
_call @ timed-call.js:13
_timedCall @ timed-call.js:16
templateCompiler @ template-loader.js:262
(anonymous) @ template-loader.js:167
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
timed-call.js:25 checkModel: 10.832ms
template-loader.js:263 Trying to compile an incompatible template version! ObjectcustomStyle: falsefooterBlock: ObjectmainBlocks: ObjectpreheaderBlock: ObjectpreheaderVisible: truesponsor: Objecttheme: ObjecttitleText: "TITLE"type: "template"__proto__: Object Array[14]0: Object1: Object2: Object3: Object4: Object5: Object6: Object7: Object8: Object9: Object10: Object11: Object12: Object13: Objectlength: 14__proto__: Array[0] ObjectcustomStyle: falsefooterBlock: ObjectmainBlocks: ObjectpreheaderBlock: ObjectpreheaderVisible: truesponsor: Objecttheme: ObjecttitleText: "TITLE"type: "template"__proto__: Object
templateCompiler @ template-loader.js:263
(anonymous) @ template-loader.js:167
i @ jquery.min.js:2
fireWith @ jquery.min.js:2
y @ jquery.min.js:4
c @ jquery.min.js:4
timed-call.js:25 initializeViewmodel: 5.356ms
fileupload.js:215 'webkitURL' is deprecated. Please use 'URL' instead.
init @ fileupload.js:215
(anonymous) @ knockout.js:72
w @ knockout.js:39
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
a.eb @ knockout.js:75
a.m.i @ knockout.js:8
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
init @ knockout.js:8
(anonymous) @ knockout.js:72
w @ knockout.js:39
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
a.eb @ knockout.js:75
g.init @ knockout-jqueryui.min.js:1
e.init @ knockout-jqueryui.min.js:1
init @ tooltips.js:32
(anonymous) @ knockout.js:72
w @ knockout.js:39
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
e @ knockout.js:111
(anonymous) @ knockout.js:112
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.Ab @ knockout.js:112
update @ knockout.js:115
update @ wysiwygs.js:176
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
e @ knockout.js:111
(anonymous) @ knockout.js:112
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.Ab @ knockout.js:112
update @ knockout.js:115
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
h @ knockout.js:70
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
e @ knockout.js:111
(anonymous) @ knockout.js:112
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.Ab @ knockout.js:112
update @ knockout.js:115
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
g @ knockout.js:69
h @ knockout.js:70
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
e @ knockout.js:111
(anonymous) @ knockout.js:112
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.Ab @ knockout.js:112
update @ knockout.js:115
update @ blocks.js:118
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
g @ knockout.js:69
h @ knockout.js:70
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
p @ knockout.js:113
a.a.Bb @ knockout.js:120
w @ knockout.js:39
a.B.i @ knockout.js:113
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.ld @ knockout.js:113
update @ knockout.js:115
update @ knockout-sortable.min.js:2
update @ extsortables.js:101
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
a.Sb @ knockout.js:76
(anonymous) @ knockout.js:110
b @ knockout.js:109
c @ knockout.js:110
e @ knockout.js:111
(anonymous) @ knockout.js:112
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
a.Ab @ knockout.js:112
update @ knockout.js:115
update @ blocks.js:118
function.a.B.i @ knockout.js:72
Qc @ knockout.js:51
Rc @ knockout.js:51
aa @ knockout.js:50
a.m.a.B @ knockout.js:49
(anonymous) @ knockout.js:72
q @ knockout.js:11
m @ knockout.js:71
h @ knockout.js:69
a.Sb @ knockout.js:76
timed-call.js:25 applyBindings: 792.778ms

Steps:

  1. I put both metadata and content into db. I just wanted to be able to edit single template.
  2. Open editor
  3. Save
  4. Reload page

Thank you for quick response! 👍

@bago
Copy link
Member

bago commented Apr 10, 2017

You inverted template and metadata in Mosaico.start, so you pass a metadata object where mosaico expects a template object and that's why it complaint.

@bago bago closed this as completed Apr 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants