<commit_before>/*
 * Copyright 2009 Kantega AS
 *
 * Licensed 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.
 */

/*
 * This script expects the following properties to be set:
 * * contextPath
 * * objectTypeMultimedia
 * * multimedia.labels.confirmDelete
 * * multimedia.labels.copypaste
 * * multimedia.labels.editpermissions
 * * multimedia.labels.foldername
 * * multimedia.labels.aksessToolsUpload
 *
 */

var currentItemIdentifier = 0;

$(document).ready(function(){
    openaksess.common.debug("multimedia.$(document).ready(): multimedia");
    openaksess.multimedia.bindMultimediaupdateEvents();
    openaksess.multimedia.bindToolButtons();
    stateHandler.init("multimediaupdate");
    var currentFolder = openaksess.admin.userpreferences.getPreference(openaksess.admin.userpreferences.keys.multimedia.currentfolder);
    if (!currentFolder) {
        openaksess.common.debug("multimedia.$(document).ready(): No state found in user preferences. Opening root element.");
        currentFolder = currentItemIdentifier;
    } else {
        currentItemIdentifier = currentFolder;
    }
    openaksess.multimedia.triggerMultimediaupdateEvent(currentItemIdentifier);//Must be fired at startup in order to load the navigator
    openaksess.multimedia.addMediaitemClickListeners();
});


/********************************************************************************
 *
 * Namespace for multimediaspecific functions and objects.
 *
 ********************************************************************************/
openaksess.multimedia = {

    /**
     * Contains the binding of all elements that are listening to the multimediaupdate event.
     * New global listeners to this event should be added here.
     */
    bindMultimediaupdateEvents : function() {
        //Enables the navigator to listen to contentupdate events. Called every time a contentupdate event is fired.
        $("#Navigator").bind("multimediaupdate", function(e, itemIdentifier){
            openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): "+e.type +" event received");
            if (!suppressNavigatorUpdate) {
                openaksess.navigate.updateNavigator(itemIdentifier, true);
            } else {
                suppressNavigatorUpdate = false;
                openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): navigationUpdate suppressed");
            }
            openaksess.navigate.updateMainPane(itemIdentifier, suppressNavigatorUpdate);
        });

        $("#Statusbar").bind("multimediaupdate", function(e, itemIdentifier){
            openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): #Statusbar has received multimediaupdate event. itemIdentifier: " + itemIdentifier);
            openaksess.multimedia.multimediastatus.disableButtons();
            $.post(properties.contextPath + "/admin/multimedia/MultimediaProperties.action", {itemIdentifier: itemIdentifier}, function(data){
                openaksess.common.debug("openaksess.multimedia.update breadcrumbs");
                openaksess.multimedia.multimediastatus.breadcrumbs(data.path);
                openaksess.multimedia.multimediastatus.enableButtons(data.enabledButtons);
            }, "json");
        });
    },

    triggerMultimediaupdateEvent : function(url) {
        openaksess.common.debug("openaksess.multimedia.triggerMultimediaupdateEvent(): mediaupdate event triggered. Url: " + url);
        openaksess.admin.userpreferences.setPreference(openaksess.admin.userpreferences.keys.multimedia.currentfolder, url);
        //Event triggering is delegated to the state handler.
        stateHandler.setState(url);
    },

    /**
     * Registers click event actions to each tool
     */
    bindToolButtons : function() {
        $("#UploadButton").click(function() {
            if ($(this).not(".disabled")) {
                openaksess.multimedia.showUploadForm();
            }
        });
        $("#NewFolderButton").click(function() {
            if ($(this).not(".disabled")) {
                openaksess.multimedia.createMediaFolder();
            }
        });
        $("#DeleteFolderButton").click(function() {
            if ($(this).not(".disabled")) {
                openaksess.multimedia.tools.deleteItem(currentItemIdentifier);
            }
        });
    },

    /**
     * Actions associated with each tool.
     */
    tools :  {
        edit: function(id) {
            openaksess.common.debug("Multimedia.edit(): id: " + id);
            window.location.href = "EditMultimedia.action?id=" + id;
        },

        deleteItem: function(id) {
            openaksess.common.debug("multimedia.Multimedia.deleteItem(): id: " + id);
            openaksess.common.modalWindow.open({title:properties.multimedia.labels.confirmDelete, iframe:true, href: properties.contextPath + "/admin/multimedia/DeleteMultimedia.action?id=" + id,width: 450, height:250});
        },

        cut: function(id) {
            openaksess.common.debug("Multimedia.cut(): id: " + id);
            MultimediaClipboardHandler.cut(id);
            $(".contextMenu").enableContextMenuItems("#paste");
            //openaksess.content.contentstatus.enableButtons(['PasteButton']);
        },
<commit_msg>AP-1254 Tool buttons are not properly disabled in the multimedia archive<commit_after>/*
 * Copyright 2009 Kantega AS
 *
 * Licensed 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.
 */

/*
 * This script expects the following properties to be set:
 * * contextPath
 * * objectTypeMultimedia
 * * multimedia.labels.confirmDelete
 * * multimedia.labels.copypaste
 * * multimedia.labels.editpermissions
 * * multimedia.labels.foldername
 * * multimedia.labels.aksessToolsUpload
 *
 */

var currentItemIdentifier = 0;

$(document).ready(function(){
    openaksess.common.debug("multimedia.$(document).ready(): multimedia");
    openaksess.multimedia.bindMultimediaupdateEvents();
    openaksess.multimedia.bindToolButtons();
    stateHandler.init("multimediaupdate");
    var currentFolder = openaksess.admin.userpreferences.getPreference(openaksess.admin.userpreferences.keys.multimedia.currentfolder);
    if (!currentFolder) {
        openaksess.common.debug("multimedia.$(document).ready(): No state found in user preferences. Opening root element.");
        currentFolder = currentItemIdentifier;
    } else {
        currentItemIdentifier = currentFolder;
    }
    openaksess.multimedia.triggerMultimediaupdateEvent(currentItemIdentifier);//Must be fired at startup in order to load the navigator
    openaksess.multimedia.addMediaitemClickListeners();
});


/********************************************************************************
 *
 * Namespace for multimediaspecific functions and objects.
 *
 ********************************************************************************/
openaksess.multimedia = {

    /**
     * Contains the binding of all elements that are listening to the multimediaupdate event.
     * New global listeners to this event should be added here.
     */
    bindMultimediaupdateEvents : function() {
        //Enables the navigator to listen to contentupdate events. Called every time a contentupdate event is fired.
        $("#Navigator").bind("multimediaupdate", function(e, itemIdentifier){
            openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): "+e.type +" event received");
            if (!suppressNavigatorUpdate) {
                openaksess.navigate.updateNavigator(itemIdentifier, true);
            } else {
                suppressNavigatorUpdate = false;
                openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): navigationUpdate suppressed");
            }
            openaksess.navigate.updateMainPane(itemIdentifier, suppressNavigatorUpdate);
        });

        $("#Statusbar").bind("multimediaupdate", function(e, itemIdentifier){
            openaksess.common.debug("openaksess.multimedia.bindMultimediaupdateEvents(): #Statusbar has received multimediaupdate event. itemIdentifier: " + itemIdentifier);
            openaksess.multimedia.multimediastatus.disableButtons();
            $.post(properties.contextPath + "/admin/multimedia/MultimediaProperties.action", {itemIdentifier: itemIdentifier}, function(data){
                openaksess.common.debug("openaksess.multimedia.update breadcrumbs");
                openaksess.multimedia.multimediastatus.breadcrumbs(data.path);
                openaksess.multimedia.multimediastatus.enableButtons(data.enabledButtons);
            }, "json");
        });
    },

    triggerMultimediaupdateEvent : function(url) {
        openaksess.common.debug("openaksess.multimedia.triggerMultimediaupdateEvent(): mediaupdate event triggered. Url: " + url);
        openaksess.admin.userpreferences.setPreference(openaksess.admin.userpreferences.keys.multimedia.currentfolder, url);
        //Event triggering is delegated to the state handler.
        stateHandler.setState(url);
    },

    /**
     * Registers click event actions to each tool
     */
    bindToolButtons : function() {
        $("#UploadButton").click(function() {
            if (!$(this).hasClass("disabled")) {
                openaksess.multimedia.showUploadForm();
            }
        });
        $("#NewFolderButton").click(function() {
            if (!$(this).hasClass("disabled")) {
                openaksess.multimedia.createMediaFolder();
            }
        });
        $("#DeleteFolderButton").click(function() {
            if (!$(this).hasClass("disabled")) {
                openaksess.multimedia.tools.deleteItem(currentItemIdentifier);
            }
        });
    },

    /**
     * Actions associated with each tool.
     */
    tools :  {
        edit: function(id) {
            openaksess.common.debug("Multimedia.edit(): id: " + id);
            window.location.href = "EditMultimedia.action?id=" + id;
        },

        deleteItem: function(id) {
            openaksess.common.debug("multimedia.Multimedia.deleteItem(): id: " + id);
            openaksess.common.modalWindow.open({title:properties.multimedia.labels.confirmDelete, iframe:true, href: properties.contextPath + "/admin/multimedia/DeleteMultimedia.action?id=" + id,width: 450, height:250});
        },

        cut: function(id) {
            openaksess.common.debug("Multimedia.cut(): id: " + id);
            MultimediaClipboardHandler.cut(id);
            $(".contextMenu").enableContextMenuItems("#paste");
            //openaksess.content.contentstatus.enableButtons(['PasteButton']);
        },

{'fraction_non_alphanumeric': 0.13828502415458938, 'fraction_numerical': 0.002933057280883368, 'mean_word_length': 3.229478292593944, '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': '5037327', 'n_tokens_mistral': 2982, 'n_tokens_neox': 2901, 'n_words': 618}