# all files / keystone/lib/list/ getDocumentName.js

60% Statements 3/5
0% Branches 0/4
0% Functions 0/1
60% Lines 3/5

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    211×

    1×

    1×
     var utils = require('keystone-utils');

    /**
     * Gets the name of the provided document from the correct path
     *
     * Example:
     *     var name = list.getDocumentName(item)
     *
     * @param {Object} item
     * @param {Boolean} escape - causes HTML entities to be encoded
     */
    function getDocumentName (doc, escape) {
    	// console.log('getting document name for ' + doc.id, 'nameField: ' + this.nameField, 'namePath: ' + this.namePath);
    	// console.log('raw name value: ', doc.get(this.namePath));
    	// if (this.nameField) console.log('formatted name value: ', this.nameField.format(doc));
    	var name = String(this.nameField ? this.nameField.format(doc) : doc.get(this.namePath));
    	return (escape) ? utils.encodeHTMLEntities(name) : name;
    }

    module.exports = getDocumentName;