<commit_before>/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.
 */

var up = up || {};

(function($, fluid){
    
    /**
     * Populate a permissions form according to the presence or absence of
     * CSS classes on the specified element.
     * 
     * @param that      layout manager instance
     * @param element   HTML element with permission CSS classes
     */
    var populateForm = function(that, element) {

        // set the hidden portlet ID attribute
        var form = that.locate("permissionsDialog").find("form");
        form.find("[name=nodeId]").val(that.options.nodeIdExtractor(element));
        
        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.movable)) {
            form.find("[name=movable]").attr("checked", "checked");
        } else {
            form.find("[name=movable]").removeAttr("checked");
        }

        // set the deletable permission
        if (element.hasClass(that.options.cssClassNames.deletable)) {
            form.find("[name=deletable]").attr("checked", "checked");
        } else {
            form.find("[name=deletable]").removeAttr("checked");
        }

        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.editable)) {
            form.find("[name=editable]").attr("checked", "checked");
        } else {
            form.find("[name=editable]").removeAttr("checked");
        }

        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.addChildAllowed)) {
            form.find("[name=addChildAllowed]").attr("checked", "checked");
        } else {
            form.find("[name=addChildAllowed]").removeAttr("checked");
        }

        var title = that.options.titleExtractor(element);
        that.locate("formTitle").html(title);
        
    };

    /**
     * Update the persisted permissions for a portal page according to the
     * selections in the submitted form.
     * 
     * @param that      layout manager instance
     * @param form      permissions form
     * @return
     */
    var updatePermissions = function(that, element) {
        var newPermissions = persistPermissions(that, that.locate("permissionsDialog").find("form")[0]);
        updatePermissionClasses(that, element, newPermissions);

        that.locate("permissionsDialog").dialog("close");
        that.events.onUpdatePermissions.fire(element, newPermissions);
        return false;
    }
    
    /**
     * Save the permissions from the supplied form to the layout
     * 
     * @param that      layout manager instance
     * @param form      permissions form
     * @return array of newly-persisted permissions
     */
    var persistPermissions = function(that, form) {
        var data = {};
        
        // construct an appropriate data object from the form
        data.elementID = $(form).find("[name=nodeId]").val();
        data.action = "updatePermissions";
        data.deletable = $(form).find("[name=deletable]").attr("checked");
        data.movable = $(form).find("[name=movable]").attr("checked");
        
        if ($(form.edit)) {
            data.editable = $(form).find("[name=editable]").attr("checked");
        }
        if ($(form.canAddChild)) {
            data.addChildAllowed = $(form).find("[name=addChildAllowed]").attr("checked");
        }
        
        $.post(that.options.savePermissionsUrl, data, null, "json");
        
        var permissions = {
            deletable: data.deletable,
            movable: data.movable,
            editable: data.editable,
            addChildAllowed: data.addChildAllowed
        };
        return permissions;
        
    };
    
    /**
     * Update the permission-related classes on an element, according to the
     * supplied array of permissions.
     * 
     * @param element
     * @param permissions
     * @return
     */
    var updatePermissionClasses = function(that, element, permissions) {<commit_msg>UP-3177 Fixing logic for examining DLM fragment permissions form<commit_after>/*
 * Licensed to Jasig under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Jasig licenses this file to you 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.
 */

var up = up || {};

(function($, fluid){
    
    /**
     * Populate a permissions form according to the presence or absence of
     * CSS classes on the specified element.
     * 
     * @param that      layout manager instance
     * @param element   HTML element with permission CSS classes
     */
    var populateForm = function(that, element) {

        // set the hidden portlet ID attribute
        var form = that.locate("permissionsDialog").find("form");
        form.find("[name=nodeId]").val(that.options.nodeIdExtractor(element));
        
        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.movable)) {
            form.find("[name=movable]").attr("checked", "checked");
        } else {
            form.find("[name=movable]").removeAttr("checked");
        }

        // set the deletable permission
        if (element.hasClass(that.options.cssClassNames.deletable)) {
            form.find("[name=deletable]").attr("checked", "checked");
        } else {
            form.find("[name=deletable]").removeAttr("checked");
        }

        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.editable)) {
            form.find("[name=editable]").attr("checked", "checked");
        } else {
            form.find("[name=editable]").removeAttr("checked");
        }

        // set the movable permission
        if (element.hasClass(that.options.cssClassNames.addChildAllowed)) {
            form.find("[name=addChildAllowed]").attr("checked", "checked");
        } else {
            form.find("[name=addChildAllowed]").removeAttr("checked");
        }

        var title = that.options.titleExtractor(element);
        that.locate("formTitle").html(title);
        
    };

    /**
     * Update the persisted permissions for a portal page according to the
     * selections in the submitted form.
     * 
     * @param that      layout manager instance
     * @param form      permissions form
     * @return
     */
    var updatePermissions = function(that, element) {
        var newPermissions = persistPermissions(that, that.locate("permissionsDialog").find("form")[0]);
        updatePermissionClasses(that, element, newPermissions);

        that.locate("permissionsDialog").dialog("close");
        that.events.onUpdatePermissions.fire(element, newPermissions);
        return false;
    }
    
    /**
     * Save the permissions from the supplied form to the layout
     * 
     * @param that      layout manager instance
     * @param form      permissions form
     * @return array of newly-persisted permissions
     */
    var persistPermissions = function(that, form) {
        var data = {};
        
        // construct an appropriate data object from the form
        data.elementID = $(form).find("[name=nodeId]").val();
        data.action = "updatePermissions";
        data.deletable = $(form.deletable).attr("checked") === "checked";
        data.movable = $(form.movable).attr("checked") === "checked";
        
        if (form.editable) {
            data.editable = $(form.editable).attr("checked") === "checked";
        }
        if (form.addChildAllowed) {
            data.addChildAllowed = $(form.addChildAllowed).attr("checked") === "checked";
        }
        
        $.post(that.options.savePermissionsUrl, data, null, "json");
        
        var permissions = {
            deletable: data.deletable,
            movable: data.movable,
            editable: data.editable,
            addChildAllowed: data.addChildAllowed
        };
        return permissions;
        
    };
    
    /**
     * Update the permission-related classes on an element, according to the
     * supplied array of permissions.
     * 
     * @param element
     * @param permissions
     * @return
     */
    var updatePermissionClasses = function(that, element, permissions) {
{'fraction_non_alphanumeric': 0.11749125966733764, 'fraction_numerical': 0.001483207966945651, 'mean_word_length': 2.475699558173785, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1225897', 'n_tokens_mistral': 2448, 'n_tokens_neox': 2465, 'n_words': 686}