<commit_before>define(["jquery", "app", "marionette", "backbone", "underscore", "core/view.base", "core/basicModel"],
    function($, app, Marionette, Backbone, _, ViewBase, ModelBase) {

        var TemplateView = ViewBase.extend({
            tagName: "li",
            template: "wkhtmltopdf-template",

            initialize: function() {
                _.bindAll(this, "isFilled");
            },

            isFilled: function() {
                return this.model.isDirty();
            },

            onClose: function() {
                this.model.templateModel.unbind("api-overrides", this.model.apiOverride, this.model);
            }
        });

        var Model = ModelBase.extend({
            setTemplate: function (templateModel) {
                this.templateModel = templateModel;

                if (templateModel.get("wkhtmltopdf")) {
                    if (templateModel.get("wkhtmltopdf").isModel)
                        this.set(templateModel.get("wkhtmltopdf").toJSON());
                    else
                        this.set(templateModel.get("wkhtmltopdf"));
                }

                templateModel.set("wkhtmltopdf", this, { silent: true});

                if (this.get("orientation") == null)
                    this.set("orientation", "portrait");


                if (this.get("pageSize") == null) {
                    this.set("pageSize", "A4");
                }

                this.listenTo(this, "change", function() {
                    templateModel.trigger("change");
                });

                this.listenTo(templateModel, "api-overrides", this.apiOverride);
            },

            isDirty: function() {
                return this.get("margin") != null || this.get("header") != null || this.get("footer") != null ||
                    this.get("width") != null || this.get("height") != null || this.get("orientation") !== "portrait" ||
                    this.get("format") !== "A4" || this.get("printDelay");
            },

            apiOverride: function(req) {
                req.template.wkhtmltopdf = {
                    orientation: this.get("orientation") || "...",
                    header: this.get("header") || "...",
                    footer: this.get("footer") || "...",
                    headerHeight: this.get("headerHeight") || "...",
                    footerHeight: this.get("footerHeight") || "...",
                    marginBottom: this.get("marginBottom") || "...",
                    orientation: this.get("orientation") || "...",
                    marginLeft: this.get("marginLeft") || "...",
                    marginRight: this.get("marginRight") || "...",
                    marginTop: this.get("marginTop") || "...",
                    pageSize: this.get("pageSize") || "...",
                    pageHeight: this.get("pageHeight") || "...",
                    pageWidth: this.get("pageWidth") || "...",
                    toc: this.get("toc") || "...",
                    tocHeaderText: this.get("tocHeaderText") || "...",
                    tocLevelIndentation: this.get("tocLevelIndentation") || "..."                    ,
                    tocTextSizeShrink: this.get("tocTextSizeShrink") || "..."
                };
            }
        });

        app.on("template-extensions-render", function(context) {
            var view;

            function renderRecipeMenu() {
                if (context.template.get("recipe") === "wkhtmltopdf") {
                    var model = new Model();
                    model.setTemplate(context.template);
                    view = new TemplateView({ model: model});
                    
                    context.extensionsRegion.show(view, "wkhtmltopdf");
                } else {
                    if (view != null)<commit_msg>wait until other view unbinds before rendering<commit_after>define(["jquery", "app", "marionette", "backbone", "underscore", "core/view.base", "core/basicModel"],
    function($, app, Marionette, Backbone, _, ViewBase, ModelBase) {

        var TemplateView = ViewBase.extend({
            tagName: "li",
            template: "wkhtmltopdf-template",

            initialize: function() {
                _.bindAll(this, "isFilled");
            },

            isFilled: function() {
                return this.model.isDirty();
            },

            onClose: function() {
                this.model.templateModel.unbind("api-overrides", this.model.apiOverride, this.model);
            }
        });

        var Model = ModelBase.extend({
            setTemplate: function (templateModel) {
                this.templateModel = templateModel;

                if (templateModel.get("wkhtmltopdf")) {
                    if (templateModel.get("wkhtmltopdf").isModel)
                        this.set(templateModel.get("wkhtmltopdf").toJSON());
                    else
                        this.set(templateModel.get("wkhtmltopdf"));
                }

                templateModel.set("wkhtmltopdf", this, { silent: true});

                if (this.get("orientation") == null)
                    this.set("orientation", "portrait");


                if (this.get("pageSize") == null) {
                    this.set("pageSize", "A4");
                }

                this.listenTo(this, "change", function() {
                    templateModel.trigger("change");
                });

                this.listenTo(templateModel, "api-overrides", this.apiOverride);
            },

            isDirty: function() {
                return this.get("margin") != null || this.get("header") != null || this.get("footer") != null ||
                    this.get("width") != null || this.get("height") != null || this.get("orientation") !== "portrait" ||
                    this.get("format") !== "A4" || this.get("printDelay");
            },

            apiOverride: function(req) {
                req.template.wkhtmltopdf = {
                    orientation: this.get("orientation") || "...",
                    header: this.get("header") || "...",
                    footer: this.get("footer") || "...",
                    headerHeight: this.get("headerHeight") || "...",
                    footerHeight: this.get("footerHeight") || "...",
                    marginBottom: this.get("marginBottom") || "...",
                    orientation: this.get("orientation") || "...",
                    marginLeft: this.get("marginLeft") || "...",
                    marginRight: this.get("marginRight") || "...",
                    marginTop: this.get("marginTop") || "...",
                    pageSize: this.get("pageSize") || "...",
                    pageHeight: this.get("pageHeight") || "...",
                    pageWidth: this.get("pageWidth") || "...",
                    toc: this.get("toc") || "...",
                    tocHeaderText: this.get("tocHeaderText") || "...",
                    tocLevelIndentation: this.get("tocLevelIndentation") || "..."                    ,
                    tocTextSizeShrink: this.get("tocTextSizeShrink") || "..."
                };
            }
        });

        app.on("template-extensions-render", function(context) {
            var view;

            function renderRecipeMenu() {
                if (context.template.get("recipe") === "wkhtmltopdf") {
                    var model = new Model();
                    model.setTemplate(context.template);
                    view = new TemplateView({ model: model});

                    setTimeout(function() {
                        context.extensionsRegion.show(view, "wkhtmltopdf");
                    }, 0);
                } else {
                    if (view != null)
{'fraction_non_alphanumeric': 0.16071428571428573, 'fraction_numerical': 0.0006469979296066253, 'mean_word_length': 1.4389397286210162, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7084373', 'n_tokens_mistral': 2070, 'n_tokens_neox': 1884, 'n_words': 305}