<commit_before>$.extend(true, doaj, {

    adminApplicationsSearch : {
        activeEdges : {},

        relatedJournal : function (val, resultobj, renderer) {
            var result = "";
            if (resultobj.admin) {
                var journals_url = doaj.adminApplicationsSearchConfig.journalsUrl;
                if (resultobj.admin.current_journal) {
                    var fvurl = journals_url + '?source=%7B"query"%3A%7B"query_string"%3A%7B"query"%3A"' + resultobj.admin.current_journal + '"%2C"default_operator"%3A"AND"%7D%7D%2C"from"%3A0%2C"size"%3A10%7D';
                    result += "Update Request For: " + resultobj.admin.current_journal + '';
                }
                if (resultobj.admin.related_journal) {
                     var fvurl = journals_url + '?source=%7B"query"%3A%7B"query_string"%3A%7B"query"%3A"' + resultobj.admin.related_journal + '"%2C"default_operator"%3A"AND"%7D%7D%2C"from"%3A0%2C"size"%3A10%7D';
                    if (result != "") {
                        result += "
";
                    }
                    result += "Produced Journal: " + resultobj.admin.related_journal + '';
                }
            }
            return result;
        },

        adminStatusMap: function(value) {
            if (doaj.valueMaps.applicationStatus.hasOwnProperty(value)) {
                return doaj.valueMaps.applicationStatus[value];
            }
            return value;
        },

        init : function(params) {
            if (!params) { params = {} }

            var current_domain = document.location.host;
            var current_scheme = window.location.protocol;

            var selector = params.selector || "#admin_applications";
            var search_url = current_scheme + "//" + current_domain + doaj.adminApplicationsSearchConfig.searchPath;

            var countFormat = edges.numFormat({
                thousandsSeparator: ","
            });

            var components = [
                // facets
                edges.newRefiningANDTermSelector({
                    id: "application_status",
                    category: "facet",
                    field: "admin.application_status.exact",
                    display: "Application Status",
                    deactivateThreshold : 1,
                    valueFunction : doaj.adminApplicationsSearch.adminStatusMap,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "application_type",
                    category: "facet",
                    field: "index.application_type.exact",
                    display: "Record type",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "has_editor_group",
                    category: "facet",
                    field: "index.has_editor_group.exact",
                    display: "Has Editor Group?",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "has_editor",
                    category: "facet",
                    field: "index.has_editor.exact",
                    display: "Has Associate Editor?",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "editor_group",
                    category: "facet",
                    field: "admin.editor_group.exact",
                    display: "Editor Group",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "editor",
                    category: "facet",
                    field: "admin.editor.exact",
                    display: "Editor",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "author_pays",
                    category: "facet",
                    field: "index.has_apc.exact",
                    display: "Publication charges?",
                    deactivateThreshold: 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "classification",
                    category: "facet",
                    field: "index.classification.exact",
                    display: "Classification",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "language",
                    category: "facet",
                    field: "index.language.exact",
                    display: "Journal Language",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "country_publisher",
                    category: "facet",
                    field: "index.country.exact",
                    display: "Country of publisher",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "subject",
                    category: "facet",
                    field: "index.subject.exact",
                    display: "Subject",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "publisher",
                    category: "facet",
                    field: "bibjson.publisher.name.exact",
                    display: "Publisher",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "journal_license",
                    category: "facet",
                    field: "index.license.exact",
                    display: "Journal License",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),

                // configure the search controller
                edges.newFullSearchController({
                    id: "search-controller",
                    category: "controller",
                    sortOptions: [
                        {'display':'Date applied','field':'admin.date_applied'},
                        {'display':'Last updated','field':'last_manual_update'},   // Note: last updated on UI points to when last updated by a person (via form)
                        {'display':'Title','field':'index.unpunctitle.exact'}
                    ],
                    fieldOptions: [
                        {'display':'Title','field':'index.title'},
                        {'display':'Keywords','field':'bibjson.keywords'},
                        {'display':'Classification','field':'index.classification'},
                        {'display':'ISSN', 'field':'index.issn.exact'},
                        {'display':'Country of publisher','field':'index.country'},
                        {'display':'Journal Language','field':'index.language'},
                        {'display':'Publisher','field':'bibjson.publisher.name'},

                        {'display':'Journal: Alternative Title','field':'bibjson.alternative_title'}
                    ],
                    defaultOperator: "AND",
                    renderer: doaj.renderers.newFullSearchControllerRenderer({
                        freetextSubmitDelay: -1,
                        searchButton: true,
                        searchPlaceholder: "Search All Applications"
                    })
                }),

                // the pager, with the explicitly set page size options (see the openingQuery for the initial size)
                edges.newPager({
                    id: "top-pager",
                    category: "top-pager",
                    renderer: edges.bs3.newPagerRenderer({
                        sizeOptions: [10, 25, 50, 100],
                        numberFormat: countFormat,
                        scrollSelector: "html, body"
                    })
                }),
                edges.newPager({
                    id: "bottom-pager",
                    category: "bottom-pager",
                    renderer: edges.bs3.newPagerRenderer({
                        sizeOptions: [10, 25, 50, 100],
                        numberFormat: countFormat,
                        scrollSelector: "html, body"
                    })
                }),

                // results display
                edges.newResultsDisplay({
                    id: "results",
                    category: "results",
                    renderer: edges.bs3.newResultsFieldsByRowRenderer({
                        rowDisplay : [
                            [
                                {
                                    valueFunction: doaj.fieldRender.titleField
                                }
                            ],
                            [
                                {
                                    "pre": 'Alternative title: ',
                                    "field": "bibjson.alternative_title",
                                    "post": ""
                                }
                            ],
                            [
                                {
                                    "pre": "Date applied: ",
                                    valueFunction: doaj.fieldRender.suggestedOn
                                }
                            ],
                            [
                                {
                                    "pre": "Last updated: ",
                                    valueFunction: doaj.fieldRender.lastManualUpdate
                                }
                            ],
                            [
                                {
                                    "pre" : "Owner: ",
                                    valueFunction: doaj.fieldRender.owner
                                }
                            ],
                            [
                                {
                                    "pre" : "ISSN(s): ",
                                    valueFunction: doaj.fieldRender.issns
                                }
                            ],
                            [
                                {
                                    "pre" : "Application status: ",
                                    valueFunction: doaj.fieldRender.applicationStatus
                                }
                            ],
                            [
                                {
                                    "pre" : "Editor Group: ",
                                    "field" : "admin.editor_group"
                                }
                            ],
                            [
                                {
                                    "pre": "Classification: ",
                                    "field": "index.classification"
                                }
                            ],
                            [
                                {
                                    "pre": "Keywords: ",
                                    "field": "bibjson.keywords"
                                }
                            ],
                            [
                                {
                                    "pre": "Publisher: ",
                                    "field": "bibjson.publisher.name"
                                }
                            ],
                            [
                                {
                                    "pre": "Publication charges?: ",
                                    valueFunction: doaj.fieldRender.authorPays
                                }
                            ],
                            [
                                {
                                    "pre": "Country of publisher: ",
                                    valueFunction: doaj.fieldRender.countryName
                                }
                            ],
                            [
                                {
                                    "pre": "Journal Language: ",
                                    "field": "bibjson.language"
                                }
                            ],
                            [
                                {
                                    "pre": "Journal License: ",
                                    valueFunction: doaj.fieldRender.journalLicense
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.fieldRender.links
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.adminApplicationsSearch.relatedJournal
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.fieldRender.readOnlyJournal({
                                        readOnlyJournalUrl : doaj.adminApplicationsSearchConfig.readOnlyJournalUrl
                                    })
                                },
                                {
                                    valueFunction: doaj.fieldRender.editSuggestion({
                                        editUrl : doaj.adminApplicationsSearchConfig.applicationEditUrl
                                    })
                                }
                            ]
                        ]
                    })
                }),

                // selected filters display, with all the fields given their display names
                edges.newSelectedFilters({
                    id: "selected-filters",
                    category: "selected-filters",
                    fieldDisplays: {
                        'admin.application_status.exact': 'Application Status',
                        'index.application_type.exact' : 'Record type',
                        'index.has_editor_group.exact' : 'Has Editor Group?',
                        'index.has_editor.exact' : 'Has Associate Editor?',
                        'admin.editor_group.exact' : 'Editor Group',
                        'admin.editor.exact' : 'Editor',
                        'index.classification.exact' : 'Classification',
                        'index.language.exact' : 'Journal Language',
                        'index.country.exact' : 'Country of publisher',
                        'index.subject.exact' : 'Subject',
                        'bibjson.publisher.name.exact' : 'Publisher',
                        'bibjson.provider.exact' : 'Platform, Host, Aggregator',
                        "index.has_apc.exact" : "Publication charges?",
                        'index.license.exact' : 'Journal License'
                    },
                    valueMaps : {
                        "bibjson.author_pays.exact" : {
                            "N" : "No",
                            "Y" : "Yes",
                            "NY" : "No Information",
                            "CON" : "Conditional"
                        }
                    }
                }),

                // the standard searching notification
                edges.newSearchingNotification({
                    id: "searching-notification",
                    category: "searching-notification"
                })
            ];

            var e = edges.newEdge({
                selector: selector,
                template: edges.bs3.newFacetview(),
                search_url: search_url,
                manageUrl: true,
                openingQuery : es.newQuery({
                    sort: {"field" : "admin.date_applied", "order" : "asc"}
                }),
                components: components,
                callbacks : {
                    "edges:query-fail" : function() {
                        alert("There was an unexpected error.  Please reload the page and try again.  If the issue persists please contact an administrator.");
                    }
                }
            });
            doaj.adminApplicationsSearch.activeEdges[selector] = e;

            var mfb = doaj.multiFormBox.newMultiFormBox({
                edge : e,
                selector: "#admin-bulk-box",
                bindings : {
                    editor_group : function(context) {
                        autocomplete($('#editor_group', context), 'name', 'editor_group', 1, false);
                    }
                },
                validators : {
                    application_status : function(context) {
                        var val = context.find("#application_status").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    },
                    editor_group : function(context) {
                        var val = context.find("#editor_group").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    },
                    note : function(context) {
                        var val = context.find("#note").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    }
                },
                submit : {
                    note : {
                        data: function(context) {
                            return {
                                note: $('#note', context).val()
                            };
                        }
                    },
                    editor_group : {
                        data : function(context) {
                            return {
                                editor_group: $('#editor_group', context).val()
                            };
                        }
                    },
                    application_status : {
                        data : function(context) {
                            return {
                                application_status: $('#application_status', context).val()
                            };
                        }
                    }
                },
                urls : {
                    note : "/admin/applications/bulk/add_note",
                    editor_group : "/admin/applications/bulk/assign_editor_group",
                    application_status : "/admin/applications/bulk/change_status"
                }
            });
            doaj.multiFormBox.active = mfb;

            $(selector).on("edges:pre-render", function() {
                doaj.multiFormBox.active.validate();
            });
        }
    }
});

jQuery(document).ready(function($) {
    doaj.adminApplicationsSearch.init();
});
<commit_msg>update admin search UI language to better represent rejected update requests<commit_after>$.extend(true, doaj, {

    adminApplicationsSearch : {
        activeEdges : {},

        relatedJournal : function (val, resultobj, renderer) {
            var result = "";
            if (resultobj.admin) {
                var journals_url = doaj.adminApplicationsSearchConfig.journalsUrl;
                if (resultobj.admin.current_journal) {
                    var fvurl = journals_url + '?source=%7B"query"%3A%7B"query_string"%3A%7B"query"%3A"' + resultobj.admin.current_journal + '"%2C"default_operator"%3A"AND"%7D%7D%2C"from"%3A0%2C"size"%3A10%7D';
                    result += "Update Request For: " + resultobj.admin.current_journal + '';
                }
                if (resultobj.admin.related_journal) {
                     var fvurl = journals_url + '?source=%7B"query"%3A%7B"query_string"%3A%7B"query"%3A"' + resultobj.admin.related_journal + '"%2C"default_operator"%3A"AND"%7D%7D%2C"from"%3A0%2C"size"%3A10%7D';
                    if (result != "") {
                        result += "
";
                    }
                    let label = "Produced Journal";
                    if (resultobj.admin.application_status === "rejected") {
                        label = "Originally For Journal";
                    }
                    result += "" + label + ": " + resultobj.admin.related_journal + '';
                }
            }
            return result;
        },

        adminStatusMap: function(value) {
            if (doaj.valueMaps.applicationStatus.hasOwnProperty(value)) {
                return doaj.valueMaps.applicationStatus[value];
            }
            return value;
        },

        init : function(params) {
            if (!params) { params = {} }

            var current_domain = document.location.host;
            var current_scheme = window.location.protocol;

            var selector = params.selector || "#admin_applications";
            var search_url = current_scheme + "//" + current_domain + doaj.adminApplicationsSearchConfig.searchPath;

            var countFormat = edges.numFormat({
                thousandsSeparator: ","
            });

            var components = [
                // facets
                edges.newRefiningANDTermSelector({
                    id: "application_status",
                    category: "facet",
                    field: "admin.application_status.exact",
                    display: "Application Status",
                    deactivateThreshold : 1,
                    valueFunction : doaj.adminApplicationsSearch.adminStatusMap,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "application_type",
                    category: "facet",
                    field: "index.application_type.exact",
                    display: "Record type",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "has_editor_group",
                    category: "facet",
                    field: "index.has_editor_group.exact",
                    display: "Has Editor Group?",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "has_editor",
                    category: "facet",
                    field: "index.has_editor.exact",
                    display: "Has Associate Editor?",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "editor_group",
                    category: "facet",
                    field: "admin.editor_group.exact",
                    display: "Editor Group",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "editor",
                    category: "facet",
                    field: "admin.editor.exact",
                    display: "Editor",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "author_pays",
                    category: "facet",
                    field: "index.has_apc.exact",
                    display: "Publication charges?",
                    deactivateThreshold: 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "classification",
                    category: "facet",
                    field: "index.classification.exact",
                    display: "Classification",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "language",
                    category: "facet",
                    field: "index.language.exact",
                    display: "Journal Language",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "country_publisher",
                    category: "facet",
                    field: "index.country.exact",
                    display: "Country of publisher",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "subject",
                    category: "facet",
                    field: "index.subject.exact",
                    display: "Subject",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "publisher",
                    category: "facet",
                    field: "bibjson.publisher.name.exact",
                    display: "Publisher",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),
                edges.newRefiningANDTermSelector({
                    id: "journal_license",
                    category: "facet",
                    field: "index.license.exact",
                    display: "Journal License",
                    deactivateThreshold : 1,
                    renderer: edges.bs3.newRefiningANDTermSelectorRenderer({
                        controls: true,
                        open: false,
                        togglable: true,
                        countFormat: countFormat,
                        hideInactive: true
                    })
                }),

                // configure the search controller
                edges.newFullSearchController({
                    id: "search-controller",
                    category: "controller",
                    sortOptions: [
                        {'display':'Date applied','field':'admin.date_applied'},
                        {'display':'Last updated','field':'last_manual_update'},   // Note: last updated on UI points to when last updated by a person (via form)
                        {'display':'Title','field':'index.unpunctitle.exact'}
                    ],
                    fieldOptions: [
                        {'display':'Title','field':'index.title'},
                        {'display':'Keywords','field':'bibjson.keywords'},
                        {'display':'Classification','field':'index.classification'},
                        {'display':'ISSN', 'field':'index.issn.exact'},
                        {'display':'Country of publisher','field':'index.country'},
                        {'display':'Journal Language','field':'index.language'},
                        {'display':'Publisher','field':'bibjson.publisher.name'},

                        {'display':'Journal: Alternative Title','field':'bibjson.alternative_title'}
                    ],
                    defaultOperator: "AND",
                    renderer: doaj.renderers.newFullSearchControllerRenderer({
                        freetextSubmitDelay: -1,
                        searchButton: true,
                        searchPlaceholder: "Search All Applications"
                    })
                }),

                // the pager, with the explicitly set page size options (see the openingQuery for the initial size)
                edges.newPager({
                    id: "top-pager",
                    category: "top-pager",
                    renderer: edges.bs3.newPagerRenderer({
                        sizeOptions: [10, 25, 50, 100],
                        numberFormat: countFormat,
                        scrollSelector: "html, body"
                    })
                }),
                edges.newPager({
                    id: "bottom-pager",
                    category: "bottom-pager",
                    renderer: edges.bs3.newPagerRenderer({
                        sizeOptions: [10, 25, 50, 100],
                        numberFormat: countFormat,
                        scrollSelector: "html, body"
                    })
                }),

                // results display
                edges.newResultsDisplay({
                    id: "results",
                    category: "results",
                    renderer: edges.bs3.newResultsFieldsByRowRenderer({
                        rowDisplay : [
                            [
                                {
                                    valueFunction: doaj.fieldRender.titleField
                                }
                            ],
                            [
                                {
                                    "pre": 'Alternative title: ',
                                    "field": "bibjson.alternative_title",
                                    "post": ""
                                }
                            ],
                            [
                                {
                                    "pre": "Date applied: ",
                                    valueFunction: doaj.fieldRender.suggestedOn
                                }
                            ],
                            [
                                {
                                    "pre": "Last updated: ",
                                    valueFunction: doaj.fieldRender.lastManualUpdate
                                }
                            ],
                            [
                                {
                                    "pre" : "Owner: ",
                                    valueFunction: doaj.fieldRender.owner
                                }
                            ],
                            [
                                {
                                    "pre" : "ISSN(s): ",
                                    valueFunction: doaj.fieldRender.issns
                                }
                            ],
                            [
                                {
                                    "pre" : "Application status: ",
                                    valueFunction: doaj.fieldRender.applicationStatus
                                }
                            ],
                            [
                                {
                                    "pre" : "Editor Group: ",
                                    "field" : "admin.editor_group"
                                }
                            ],
                            [
                                {
                                    "pre": "Classification: ",
                                    "field": "index.classification"
                                }
                            ],
                            [
                                {
                                    "pre": "Keywords: ",
                                    "field": "bibjson.keywords"
                                }
                            ],
                            [
                                {
                                    "pre": "Publisher: ",
                                    "field": "bibjson.publisher.name"
                                }
                            ],
                            [
                                {
                                    "pre": "Publication charges?: ",
                                    valueFunction: doaj.fieldRender.authorPays
                                }
                            ],
                            [
                                {
                                    "pre": "Country of publisher: ",
                                    valueFunction: doaj.fieldRender.countryName
                                }
                            ],
                            [
                                {
                                    "pre": "Journal Language: ",
                                    "field": "bibjson.language"
                                }
                            ],
                            [
                                {
                                    "pre": "Journal License: ",
                                    valueFunction: doaj.fieldRender.journalLicense
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.fieldRender.links
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.adminApplicationsSearch.relatedJournal
                                }
                            ],
                            [
                                {
                                    valueFunction: doaj.fieldRender.readOnlyJournal({
                                        readOnlyJournalUrl : doaj.adminApplicationsSearchConfig.readOnlyJournalUrl
                                    })
                                },
                                {
                                    valueFunction: doaj.fieldRender.editSuggestion({
                                        editUrl : doaj.adminApplicationsSearchConfig.applicationEditUrl
                                    })
                                }
                            ]
                        ]
                    })
                }),

                // selected filters display, with all the fields given their display names
                edges.newSelectedFilters({
                    id: "selected-filters",
                    category: "selected-filters",
                    fieldDisplays: {
                        'admin.application_status.exact': 'Application Status',
                        'index.application_type.exact' : 'Record type',
                        'index.has_editor_group.exact' : 'Has Editor Group?',
                        'index.has_editor.exact' : 'Has Associate Editor?',
                        'admin.editor_group.exact' : 'Editor Group',
                        'admin.editor.exact' : 'Editor',
                        'index.classification.exact' : 'Classification',
                        'index.language.exact' : 'Journal Language',
                        'index.country.exact' : 'Country of publisher',
                        'index.subject.exact' : 'Subject',
                        'bibjson.publisher.name.exact' : 'Publisher',
                        'bibjson.provider.exact' : 'Platform, Host, Aggregator',
                        "index.has_apc.exact" : "Publication charges?",
                        'index.license.exact' : 'Journal License'
                    },
                    valueMaps : {
                        "bibjson.author_pays.exact" : {
                            "N" : "No",
                            "Y" : "Yes",
                            "NY" : "No Information",
                            "CON" : "Conditional"
                        }
                    }
                }),

                // the standard searching notification
                edges.newSearchingNotification({
                    id: "searching-notification",
                    category: "searching-notification"
                })
            ];

            var e = edges.newEdge({
                selector: selector,
                template: edges.bs3.newFacetview(),
                search_url: search_url,
                manageUrl: true,
                openingQuery : es.newQuery({
                    sort: {"field" : "admin.date_applied", "order" : "asc"}
                }),
                components: components,
                callbacks : {
                    "edges:query-fail" : function() {
                        alert("There was an unexpected error.  Please reload the page and try again.  If the issue persists please contact an administrator.");
                    }
                }
            });
            doaj.adminApplicationsSearch.activeEdges[selector] = e;

            var mfb = doaj.multiFormBox.newMultiFormBox({
                edge : e,
                selector: "#admin-bulk-box",
                bindings : {
                    editor_group : function(context) {
                        autocomplete($('#editor_group', context), 'name', 'editor_group', 1, false);
                    }
                },
                validators : {
                    application_status : function(context) {
                        var val = context.find("#application_status").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    },
                    editor_group : function(context) {
                        var val = context.find("#editor_group").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    },
                    note : function(context) {
                        var val = context.find("#note").val();
                        if (val === "") {
                            return {valid: false};
                        }
                        return {valid: true};
                    }
                },
                submit : {
                    note : {
                        data: function(context) {
                            return {
                                note: $('#note', context).val()
                            };
                        }
                    },
                    editor_group : {
                        data : function(context) {
                            return {
                                editor_group: $('#editor_group', context).val()
                            };
                        }
                    },
                    application_status : {
                        data : function(context) {
                            return {
                                application_status: $('#application_status', context).val()
                            };
                        }
                    }
                },
                urls : {
                    note : "/admin/applications/bulk/add_note",
                    editor_group : "/admin/applications/bulk/assign_editor_group",
                    application_status : "/admin/applications/bulk/change_status"
                }
            });
            doaj.multiFormBox.active = mfb;

            $(selector).on("edges:pre-render", function() {
                doaj.multiFormBox.active.validate();
            });
        }
    }
});

jQuery(document).ready(function($) {
    doaj.adminApplicationsSearch.init();
});
<|endoftext|>


<commit_before>import Ember from 'ember';
import BehaviorService from 'sl-ember-behavior/services/behavior';

var BS;

module( 'Unit - services:behavior', {
    setup: function() {
        BS = BehaviorService.create();
    }
});

test( '"behaviors" property defaults to null', function() {
    equal( BS.get( 'behaviors' ), null );
});

test( 'getBehaviorGroup() requires an Object to be provided', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.getBehaviorGroup();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( { behaviorGroup: 'notUnderTest' } );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'getBehaviorGroup() "provider.behaviorGroup" must be a String or Function', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: null });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was empty' );

    // Number Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: 4 });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was a Number' );

    // Array Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: [] });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was an Array' );

    // Object Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: {} });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was an Object' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: function(){} });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Property was a Function' );

    // String Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: 'test' });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Property was a String' );
});

test( 'If getBehaviorGroup() "provider.behaviorGroup" is a string its value is returned', function() {
    var testValue = 'testGroup';

    equal( testValue, BS.getBehaviorGroup({ behaviorGroup: testValue }) );
});

test( 'If getBehaviorGroup() "provider.behaviorGroup" is a function it is executed', function() {
    var result = BS.getBehaviorGroup({
        behaviorGroup: function() {
            return 'test group';
        }
    });

    equal( 'test group', result );
});

test( 'setBehaviors() requires an Object to be provided', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.setBehaviors();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( {} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'setBehaviors() sets data on the behaviors property', function() {
    var testBehaviors = Ember.Object.create( { 'the_key': 'my value' } );

    BS.setBehaviors( testBehaviors );

    deepEqual( BS.get( 'behaviors' ), testBehaviors );
});

test( 'isAble() requires two arguments to be provided', function() {

    // No arguments

    var assertionThrown = false;

    try {
        BS.isAble();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'No arguments were provided' );

    // One argument

    assertionThrown = false;

    try {
        BS.isAble( 'one' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'One argument was provided' );

    // Two arguments

    assertionThrown = false;

    try {
        BS.isAble( 'one', 'two' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Two arguments were provided' );
});

test( 'isAble() requires first argument to be a String', function() {
    // Empty parameter

    var assertionThrown = false;

    try {
        BS.isAble();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.isAble( 4, 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.isAble( [], 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.isAble( {}, 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Object' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'test', 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was a String' );
});

test( 'isAble() requires second argument to be a String or Object', function() {
    // Number parameter

    var assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    BS.getBehaviorGroup = function() {
        return true;
    };

    try {
        BS.isAble( 'notUnderTest', {});
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'isAble() 2nd argument is a string - argument values are compared to Behavior data to make determination', function() {
    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( BS.isAble( 'reboot', 'device' ), 'Was able' );

    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'reboot', 'device' ), 'Was not able' );
});

test( 'isAble() 2nd argument is an object - getBehaviorGroup() is called', function() {
    var wasCalled = false;

    BS.getBehaviorGroup = function() {
        wasCalled = true;
    };

    BS.isAble( 'notUnderTest', {});

    ok( wasCalled, 'getBehaviorGroup() was called' );
});

test( 'isAble() 2nd argument is an object - getBehaviorGroup() value is compared to Behavior data to make determination', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return true;
            }
        }
    }) , 'getBehaviorGroup() value was compared to Behavior data' );
});

test( 'isAble() 2nd argument is an object and is allowed - "behaviors" hash refines determination', function() {
    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( !BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return false;
            }
        }
    }) , '"behaviors" hash refined determination' );

    ok( BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return true;
            }
        }
    }) , '"behaviors" hash refined determination' );
});

test( 'isUnable() is the negated result of a call to isAble()', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( BS.isUnable( 'reboot', 'device' ), 'Was unable' );

    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( !BS.isUnable( 'reboot', 'device' ), 'Was not unable' );
});
<commit_msg>Add additional tests<commit_after>import Ember from 'ember';
import BehaviorService from 'sl-ember-behavior/services/behavior';

var BS;

module( 'Unit - services:behavior', {
    setup: function() {
        BS = BehaviorService.create();
    }
});

test( '"behaviors" property defaults to null', function() {
    equal( BS.get( 'behaviors' ), null );
});

test( 'getBehaviorGroup() requires an Object to be provided', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.getBehaviorGroup();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( { behaviorGroup: 'notUnderTest' } );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'getBehaviorGroup() "provider.behaviorGroup" must be a String or Function', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: null });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was empty' );

    // Number Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: 4 });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was a Number' );

    // Array Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: [] });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was an Array' );

    // Object Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: {} });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Property was an Object' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: function(){} });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Property was a Function' );

    // String Property

    assertionThrown = false;

    try {
        BS.getBehaviorGroup({ behaviorGroup: 'test' });
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Property was a String' );
});

test( 'If getBehaviorGroup() "provider.behaviorGroup" is a string its value is returned', function() {
    var testValue = 'testGroup';

    equal( testValue, BS.getBehaviorGroup({ behaviorGroup: testValue }) );
});

test( 'If getBehaviorGroup() "provider.behaviorGroup" is a function it is executed', function() {
    var result = BS.getBehaviorGroup({
        behaviorGroup: function() {
            return 'test group';
        }
    });

    equal( 'test group', result );
});

test( 'setBehaviors() requires an Object to be provided', function() {

    // Empty parameter

    var assertionThrown = false;

    try {
        BS.setBehaviors();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.setBehaviors( {} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'setBehaviors() sets data on the behaviors property', function() {
    var testBehaviors = Ember.Object.create( { 'the_key': 'my value' } );

    BS.setBehaviors( testBehaviors );

    deepEqual( BS.get( 'behaviors' ), testBehaviors );
});

test( 'isAble() requires two arguments to be provided', function() {

    // No arguments

    var assertionThrown = false;

    try {
        BS.isAble();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'No arguments were provided' );

    // One argument

    assertionThrown = false;

    try {
        BS.isAble( 'one' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'One argument was provided' );

    // Two arguments

    assertionThrown = false;

    try {
        BS.isAble( 'one', 'two' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Two arguments were provided' );
});

test( 'isAble() requires first argument to be a String', function() {
    // Empty parameter

    var assertionThrown = false;

    try {
        BS.isAble();
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was empty' );

    // Number parameter

    assertionThrown = false;

    try {
        BS.isAble( 4, 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.isAble( [], 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.isAble( {}, 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Object' );

    // Object Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'test', 'notUnderTest' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was a String' );
});

test( 'isAble() requires second argument to be a String or Object', function() {
    // Number parameter

    var assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', 4 );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Number' );

    // Array Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', [] );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was an Array' );

    // Function

    assertionThrown = false;

    try {
        BS.getBehaviorGroup( function(){} );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( assertionThrown, 'Parameter was a Function' );

    // String Parameter

    assertionThrown = false;

    try {
        BS.isAble( 'notUnderTest', 'test' );
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was a String' );

    // Object Parameter

    assertionThrown = false;

    BS.getBehaviorGroup = function() {
        return true;
    };

    try {
        BS.isAble( 'notUnderTest', {});
    } catch( error ) {
        assertionThrown = true;
    }

    ok( !assertionThrown, 'Parameter was an Object' );
});

test( 'isAble() 2nd argument is a string - argument values are compared to Behavior data to make determination', function() {
    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( BS.isAble( 'reboot', 'device' ), 'Was able' );

    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'reboot', 'device' ), 'Was not able' );
});

test( 'isAble() 2nd argument is an object - getBehaviorGroup() is called', function() {
    var wasCalled = false;

    BS.getBehaviorGroup = function() {
        wasCalled = true;
    };

    BS.isAble( 'notUnderTest', {});

    ok( wasCalled, 'getBehaviorGroup() was called' );
});

test( 'isAble() 2nd argument is an object - getBehaviorGroup() value is compared to Behavior data to make determination', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return true;
            }
        }
    }) , 'getBehaviorGroup() value was compared to Behavior data' );
});

test( 'isAble() 2nd argument is an object and is allowed - "behaviors" hash refines determination', function() {
    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( !BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return false;
            }
        }
    }) , '"behaviors" hash refined determination' );

    ok( BS.isAble( 'reboot', {
        behaviorGroup: 'device',
        behaviors: {
            reboot: function() {
                return true;
            }
        }
    }) , '"behaviors" hash refined determination' );
});

test( 'isAble() returns false if no Behavior data has been set', function() {
    ok( !BS.isAble( 'reboot', 'device' ), 'Returned false' );
});

test( 'isAble() returns false if specified Behavior Group has not been configured', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'reboot', 'product' ), 'Returned false' );
});

test( 'isAble() returns false if specified Behavior has not been configured', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( !BS.isAble( 'restart', 'device' ), 'Returned false' );
});

test( 'isUnable() is the negated result of a call to isAble()', function() {
    BS.setBehaviors({
        device: {
            reboot: false
        }
    });

    ok( BS.isUnable( 'reboot', 'device' ), 'Was unable' );

    BS.setBehaviors({
        device: {
            reboot: true
        }
    });

    ok( !BS.isUnable( 'reboot', 'device' ), 'Was not unable' );
});
<|endoftext|>


<commit_before>export const WEEKDAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
export const WEEKEND_DAYS = ['saturday', 'sunday']
export const ALL_DAYS = [...WEEKDAYS, ...WEEKEND_DAYS]

/**
 * Extracts the day of week fields of an object (e.g. a monitoredTrip) to an array.
 * Example: { monday: truthy, tuesday: falsy, wednesday: truthy ... } => ['monday', 'wednesday' ...]
 */
export function dayFieldsToArray (monitoredTrip) {
  return ALL_DAYS.filter(day => monitoredTrip[day])
}

/**
 * Converts an array of day of week values into an object with those fields.
 * Example: ['monday', 'wednesday' ...] => { monday: true, tuesday: false, wednesday: true ... }
 */
export function arrayToDayFields (arrayOfDayTypes) {
  const result = {}
  ALL_DAYS.forEach(day => {
    result[day] = arrayOfDayTypes.includes(day)
  })
  return result
}

/**
 * Returns a FormattedMessage string for the pluralised day of week via the react-intl imperative API
 * such that i18n IDs are hardcoded and can be kept track of by format.js tools
 */
export function getFormattedDayOfWeekPlural (day, intl) {
  switch (day) {
    case 'monday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.monday'})
    case 'tuesday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.tuesday'})
    case 'wednesday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.wednesday'})
    case 'thursday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.thursday'})
    case 'friday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.friday'})
    case 'saturday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.saturday'})
    case 'sunday':
      return intl.formatMessage({id: 'common.daysOfWeekPlural.sunday'})
    default:
      return null
  }
}
<commit_msg>chore: correct typo<commit_after>export const WEEKDAYS = ['monday', 'tuesday', 'wednesday', 'thursday', 'friday']
export const WEEKEND_DAYS = ['saturday', 'sunday']
export const ALL_DAYS = [...WEEKDAYS, ...WEEKEND_DAYS]

/**
 * Extracts the day of week fields of an object (e.g. a monitoredTrip) to an array.
 * Example: { monday: truthy, tuesday: false-ey, wednesday: truthy ... } => ['monday', 'wednesday' ...]
 */
export function dayFieldsToArray(monitoredTrip) {
  return ALL_DAYS.filter((day) => monitoredTrip[day])
}

/**
 * Converts an array of day of week values into an object with those fields.
 * Example: ['monday', 'wednesday' ...] => { monday: true, tuesday: false, wednesday: true ... }
 */
export function arrayToDayFields(arrayOfDayTypes) {
  const result = {}
  ALL_DAYS.forEach((day) => {
    result[day] = arrayOfDayTypes.includes(day)
  })
  return result
}

/**
 * Returns a FormattedMessage string for the pluralised day of week via the react-intl imperative API
 * such that i18n IDs are hardcoded and can be kept track of by format.js tools
 */
export function getFormattedDayOfWeekPlural(day, intl) {
  switch (day) {
    case 'monday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.monday' })
    case 'tuesday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.tuesday' })
    case 'wednesday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.wednesday' })
    case 'thursday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.thursday' })
    case 'friday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.friday' })
    case 'saturday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.saturday' })
    case 'sunday':
      return intl.formatMessage({ id: 'common.daysOfWeekPlural.sunday' })
    default:
      return null
  }
}
<|endoftext|>


<commit_before>var cdb = require('cartodb.js');
var $ = require('jquery');
var _ = require('underscore');
var CoreView = require('backbone/core-view');
var AssetItemView = require('./asset-item-view');
var checkAndBuildOpts = require('../../../../../../helpers/required-opts');
var Backbone = require('backbone');
var loadingView = require('../../../../../loading/render-loading');
var AssetHeaderView = require('./asset-header-view');

var ErrorView = require('../../../../../error/error-view');
var errorTemplate = require('./upload-assets-error.tpl');
var template = require('./user-assets-list-view.tpl');

var REQUIRED_OPTS = [
  'assets',
  'selectedAsset'
];

var KIND = 'custom-marker';
var ASSET_HEIGHT = 48;

module.exports = CoreView.extend({
  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this._stateModel = new Backbone.Model();
    this.add_related_model(this._stateModel);

    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template);

    if (this._isLoading()) {
      this._renderLoading();
    } else if (this._hasError()) {
      this._renderError();
    } else {
      this._addHeaderView();
      this._renderAssets();
    }

    return this;
  },

  _addHeaderView: function () {
    this._assetHeaderView = new AssetHeaderView({
      editable: true,
      title: this.options.title,
      assets: this._assets
    });

    this.addView(this._assetHeaderView);
    this.$('.js-nav').append(this._assetHeaderView.render().el);

    this._assetHeaderView.bind('select-all', this._selectAllAssets, this);
    this._assetHeaderView.bind('deselect-all', this._deselectAllAssets, this);
    this._assetHeaderView.bind('remove', this._removeSelectedAssets, this);
  },

  _renderAssets: function () {
    var addAssetButton = new AssetItemView({
      model: new cdb.core.Model({
        type: 'text',
        name: '+'
      }),
      assetHeight: ASSET_HEIGHT
    });

    addAssetButton.bind('selected', function () {
      this.trigger('init-upload');
    }, this);

    this.addView(addAssetButton);

    this.$('.js-assets').append(addAssetButton.render().$el);

    this._assets.each(this._renderAsset, this);
  },

  _initBinds: function () {
    this._keyDown = this._onKeyDown.bind(this);
    $(document).on('keydown', this._keyDown);

    this._keyUp = this._onKeyUp.bind(this);
    $(document).on('keyup', this._keyUp);

    this._stateModel.on('change:status', this.render, this);
    this._assets.on('change', this._onChangeAssets, this);
  },

  _getSelectedAsset: function () {
    var selectedAssets = this._assets.where({ state: 'selected' });
    return selectedAssets && selectedAssets[0];
  },

  _getSelectedAssetsCount: function () {
    var selectedAssets = this._assets.where({ state: 'selected' });
    return selectedAssets ? selectedAssets.length : 0;
  },

  _onKeyDown: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onKeyUp: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onClickBack: function (e) {
    this.killEvent(e);
    this._stateModel.set('status', '');
  },

  _renderAsset: function (assetModel) {
    var assetItemView = new AssetItemView({
      model: assetModel,
      assetHeight: ASSET_HEIGHT,
      selectedAsset: this._selectedAsset
    });

    if (assetItemView.model.get('public_url') === this.model.get('image')) {
      assetItemView.model.set('state', 'selected');
    }

    assetItemView.bind('selected', this._selectAsset, this);

    this.$('.js-assets').append(assetItemView.render().el);
    this.addView(assetItemView);
  },

  _onChangeAssets: function () {
    if (this._getSelectedAssetsCount() === 1) {
      var selectedAsset = this._getSelectedAsset();
      this._selectedAsset.set({
        url: selectedAsset && selectedAsset.get('public_url'),
        kind: KIND
      });
    } else {
      this._selectedAsset.set({
        url: '',
        kind: ''
      });
    }
  },

  _selectAllAssets: function () {
    this._assets.each(function (assetModel) {
      assetModel.set('state', 'selected');
    });
  },

  _selectAsset: function (m) {
    if (this._shiftKeyPressed) {
      m.set('state', m.get('state') === 'selected' ? '' : 'selected');
    } else {
      m.set('state', 'selected');
    }

    if (!this._shiftKeyPressed) {
      this._deselectAllAssets2(m);
    }
  },

  _deselectAllAssets2: function (m) {
    this._assets.each(function (assetModel) {
      if (assetModel !== m && assetModel.get('state') === 'selected') {
        assetModel.set('state', '');
      }
    });
  },

  _deselectAllAssets: function () {
    this._assets.each(function (assetModel) {
      assetModel.set('state', '');
    });
  },

  _removeSelectedAssets: function () {
    this._stateModel.set('status', 'loading');

    var selectedAssets = this._assets.select(function (asset) {
      return asset.get('state') === 'selected';
    }, this);

    _.each(selectedAssets, function (asset) {
      asset.destroy({
        complete: this._onDestroyFinished.bind(this)
      });

      this.$('#' + asset.get('id')).remove();
    }, this);
  },

  _onDestroyFinished: function (response) {
    if (response.status === 200) {
      this._stateModel.set('status', '');
    } else {
      this._stateModel.set({
        error_message: response.statusText,
        status: 'error'
      });
    }
  },

  _isLoading: function () {
    return this._stateModel.get('status') === 'loading';
  },

  _hasError: function () {
    return this._stateModel.get('status') === 'error';
  },

  _renderLoading: function () {
    this.$el.html(
      loadingView({
        title: _t('components.modals.assets-picker.loading')
      })
    );
  },

  _renderError: function () {
    this.$el.html(
      new ErrorView({
        title: this._stateModel.get('error_message'),
        desc: _t('components.modals.assets-picker.error-desc'),
        template: errorTemplate
      }).render().el
    );
  },

  _disableBinds: function () {
    $(document).off('keydown', this._keyDown);
    $(document).off('keyup', this._keyUp);
  },

  clean: function () {
    this._disableBinds();
    CoreView.prototype.clean.apply(this);
  }
});
<commit_msg>Minimal refactor<commit_after>var cdb = require('cartodb.js');
var $ = require('jquery');
var _ = require('underscore');
var CoreView = require('backbone/core-view');
var AssetItemView = require('./asset-item-view');
var checkAndBuildOpts = require('../../../../../../helpers/required-opts');
var Backbone = require('backbone');
var loadingView = require('../../../../../loading/render-loading');
var AssetHeaderView = require('./asset-header-view');

var ErrorView = require('../../../../../error/error-view');
var errorTemplate = require('./upload-assets-error.tpl');
var template = require('./user-assets-list-view.tpl');

var REQUIRED_OPTS = [
  'assets',
  'selectedAsset'
];

var KIND = 'custom-marker';
var ASSET_HEIGHT = 48;

module.exports = CoreView.extend({
  initialize: function (opts) {
    checkAndBuildOpts(opts, REQUIRED_OPTS, this);

    this._initModels();
    this._initBinds();
  },

  render: function () {
    this.clearSubViews();
    this.$el.html(template);

    if (this._isLoading()) {
      this._renderLoading();
    } else if (this._hasError()) {
      this._renderError();
    } else {
      this._renderRegularView();
    }

    return this;
  },

  _addHeaderView: function () {
    this._assetHeaderView = new AssetHeaderView({
      editable: true,
      title: this.options.title,
      assets: this._assets
    });

    this.addView(this._assetHeaderView);
    this.$('.js-nav').append(this._assetHeaderView.render().el);

    this._assetHeaderView.bind('select-all', this._selectAllAssets, this);
    this._assetHeaderView.bind('deselect-all', this._deselectAllAssets, this);
    this._assetHeaderView.bind('remove', this._removeSelectedAssets, this);
  },

  _renderRegularView: function () {
    this._addHeaderView();
    this._renderAddButton();
    this._assets.each(this._renderAsset, this);
  },

  _renderAddButton: function () {
    var addAssetButton = new AssetItemView({
      model: new cdb.core.Model({
        type: 'text',
        name: '+'
      }),
      assetHeight: ASSET_HEIGHT
    });

    addAssetButton.bind('selected', function () {
      this.trigger('init-upload');
    }, this);

    this.addView(addAssetButton);
    this.$('.js-assets').append(addAssetButton.render().$el);
  },

  _initModels: function () {
    this._stateModel = new Backbone.Model();
    this.add_related_model(this._stateModel);
  },

  _initBinds: function () {
    this._keyDown = this._onKeyDown.bind(this);
    $(document).on('keydown', this._keyDown);

    this._keyUp = this._onKeyUp.bind(this);
    $(document).on('keyup', this._keyUp);

    this._stateModel.on('change:status', this.render, this);
    this._assets.on('change', this._onChangeAssets, this);
  },

  _getSelectedAsset: function () {
    var selectedAssets = this._assets.where({ state: 'selected' });
    return selectedAssets && selectedAssets[0];
  },

  _getSelectedAssetsCount: function () {
    var selectedAssets = this._assets.where({ state: 'selected' });
    return selectedAssets ? selectedAssets.length : 0;
  },

  _onKeyDown: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onKeyUp: function (ev) {
    this._shiftKeyPressed = ev.shiftKey;
  },

  _onClickBack: function (e) {
    this.killEvent(e);
    this._stateModel.set('status', '');
  },

  _renderAsset: function (assetModel) {
    var assetItemView = new AssetItemView({
      model: assetModel,
      assetHeight: ASSET_HEIGHT,
      selectedAsset: this._selectedAsset
    });

    if (assetItemView.model.get('public_url') === this.model.get('image')) {
      assetItemView.model.set('state', 'selected');
    }

    assetItemView.bind('selected', this._selectAsset, this);

    this.$('.js-assets').append(assetItemView.render().el);
    this.addView(assetItemView);
  },

  _onChangeAssets: function () {
    if (this._getSelectedAssetsCount() === 1) {
      var selectedAsset = this._getSelectedAsset();
      this._selectedAsset.set({
        url: selectedAsset && selectedAsset.get('public_url'),
        kind: KIND
      });
    } else {
      this._selectedAsset.set({
        url: '',
        kind: ''
      });
    }
  },

  _selectAllAssets: function () {
    this._assets.each(function (assetModel) {
      assetModel.set('state', 'selected');
    });
  },

  _selectAsset: function (m) {
    if (this._shiftKeyPressed) {
      m.set('state', m.get('state') === 'selected' ? '' : 'selected');
    } else {
      m.set('state', 'selected');
    }

    if (!this._shiftKeyPressed) {
      this._deselectAllExceptSelected(m);
    }
  },

  _deselectAllExceptSelected: function (m) {
    this._assets.each(function (assetModel) {
      if (assetModel !== m && assetModel.get('state') === 'selected') {
        assetModel.set('state', '');
      }
    });
  },

  _deselectAllAssets: function () {
    this._assets.each(function (assetModel) {
      assetModel.set('state', '');
    });
  },

  _removeSelectedAssets: function () {
    this._stateModel.set('status', 'loading');

    var selectedAssets = this._assets.select(function (asset) {
      return asset.get('state') === 'selected';
    }, this);

    _.each(selectedAssets, function (asset) {
      asset.destroy({
        complete: this._onDestroyFinished.bind(this)
      });

      this.$('#' + asset.get('id')).remove();
    }, this);
  },

  _onDestroyFinished: function (response) {
    if (response.status === 200) {
      this._stateModel.set('status', '');
    } else {
      this._stateModel.set({
        error_message: response.statusText,
        status: 'error'
      });
    }
  },

  _isLoading: function () {
    return this._stateModel.get('status') === 'loading';
  },

  _hasError: function () {
    return this._stateModel.get('status') === 'error';
  },

  _renderLoading: function () {
    this.$el.html(
      loadingView({
        title: _t('components.modals.assets-picker.loading')
      })
    );
  },

  _renderError: function () {
    this.$el.html(
      new ErrorView({
        title: this._stateModel.get('error_message'),
        desc: _t('components.modals.assets-picker.error-desc'),
        template: errorTemplate
      }).render().el
    );
  },

  _disableBinds: function () {
    $(document).off('keydown', this._keyDown);
    $(document).off('keyup', this._keyUp);
  },

  clean: function () {
    this._disableBinds();
    CoreView.prototype.clean.apply(this);
  }
});
<|endoftext|>