5c3cc90cb6856faee07426991aa29ea8eb45fbbb
[yaffs-website] / web / core / modules / media / js / type_form.es6.js
1 /**
2  * @file
3  * Defines JavaScript behaviors for the media type form.
4  */
5
6 (function($, Drupal) {
7   /**
8    * Behaviors for setting summaries on media type form.
9    *
10    * @type {Drupal~behavior}
11    *
12    * @prop {Drupal~behaviorAttach} attach
13    *   Attaches summary behaviors on media type edit forms.
14    */
15   Drupal.behaviors.mediaTypeFormSummaries = {
16     attach(context) {
17       const $context = $(context);
18       // Provide the vertical tab summaries.
19       $context.find('#edit-workflow').drupalSetSummary(context => {
20         const vals = [];
21         $(context)
22           .find('input[name^="options"]:checked')
23           .parent()
24           .each(function() {
25             vals.push(
26               Drupal.checkPlain(
27                 $(this)
28                   .find('label')
29                   .text(),
30               ),
31             );
32           });
33         if (
34           !$(context)
35             .find('#edit-options-status')
36             .is(':checked')
37         ) {
38           vals.unshift(Drupal.t('Not published'));
39         }
40         return vals.join(', ');
41       });
42       $(context)
43         .find('#edit-language')
44         .drupalSetSummary(context => {
45           const vals = [];
46
47           vals.push(
48             $(context)
49               .find(
50                 '.js-form-item-language-configuration-langcode select option:selected',
51               )
52               .text(),
53           );
54
55           $(context)
56             .find('input:checked')
57             .next('label')
58             .each(function() {
59               vals.push(Drupal.checkPlain($(this).text()));
60             });
61
62           return vals.join(', ');
63         });
64     },
65   };
66 })(jQuery, Drupal);