HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/RMourik/bassol.nl/wwwroot/CMSScripts/CMSModules/CMS/AttachmentsCountUpdater.js
/** 
 * Attachments count updater module
 * 
 * Subscribes to event fired by MetafileDialog when dialog is closing.
 * Updates text in element specified by selector. Appends number indicating count of the metafiles (attachments)
 */
cmsdefine(['CMS/EventHub', 'jQuery'], function (hub, $) {
    'use strict';

    /**
    * Updates inner html of element with text containing given items count. 
    *
    * @param {jQuery element} element - element to update
    * @param {String} text - element inner text
    * @param {frame} count - items count
    */
    var updateAttachmentCount = function(element, text, count) {
        if (element) {
            if (count > 0) {
                element.html(text + ' (' + count + ')');
            }
            else if (count == 0) {
                element.html(text);
            }
        }
    };
    

    /**
    * Module constructor
    */
    var AttachmentsCountModule = function (data) {
        var that = this;
       
        this.element = $(data.selector);
        this.text = data.text;

        hub.subscribe('UpdateAttachmentsCount', function (count) {
            updateAttachmentCount(that.element, that.text, count);
        });
    };
 
    return AttachmentsCountModule;
});