aboutsummaryrefslogtreecommitdiff
path: root/data/assets/js/admin/dialogs/page-edit.js
blob: 0e7a5b3d5a3f683f748b24cc643986b42f744b9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
jQuery(function($) {
  "use strict";

  var ASSET_TYPES = ['styles', 'scripts'],
      p = '#page-edit-';

  $(p + 'dialog').on('guff.loaded', function(ev) {
    var r = ev.post_data;

    $(p + 'theme').val(r.theme_id || 'site-default');

    // set assets
    $.each(ASSET_TYPES, function(i, key) {
      $(p + key).val(r[key].join("\n"));
    });
  });

  $(p + 'confirm').click(function() {
    var theme_id = $(p + 'theme').val();
    if (theme_id == 'site-default')
      theme_id = null;

    // get assets
    var assets = ASSET_TYPES.reduce(function(r, key) {
      r[key] = listify(p + key);
      return r;
    }, {});

    $(p + 'dialog').trigger({
      type: 'guff.save',

      post_data: $.extend({
        have_theme_id: 't',
        theme_id: theme_id,
      }, assets),
    });

    // stop event
    return false;
  });
});