aboutsummaryrefslogtreecommitdiff
path: root/data/stuff/test/tab-posts.js
blob: 90c26de9c82f2222bbed8af05045bb0a03bfda08 (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
jQuery(function($) {
  "use strict";

  var TEMPLATES = new LuigiTemplate.Cache({
    user: [
      "<a ",
        "href='#' ",
        "class='list-group-item %{css|h}' ",
        "title='Edit user \"%{user_name|h}\".' ",
        "data-row='%{row|json|h}' ",
        "data-q='%{q|h}' ",
      ">",
        "<i class='fa fa-fw fa-spinner fa-spin hidden loading'></i>",
        "<i class='fa fa-fw fa-user loading'></i>",
        " ",
        "%{user_name|h} (%{email|h})",

        "<span class='badge pull-right'>",
          "%{role_name|h}",
        "</span>",
      "</a>",
    ],

    loading: [
      "<span class='list-group-item disabled'>",
        "<i class='fa fa-spinner fa-spin'></i>",
        " ",
        "Loading...",
      "</span>",
    ],

    error: [
      "<span class='list-group-item list-group-item-danger disabled'>",
        "<i class='fa fa-exclamation-triangle'></i>",
        " ",
        "Error: %{responseText|h}",
      "</span>",
    ],
  });

  $.each(['blog', 'page', 'project'], function(i, id) {
    var p = '#' + id + '-edit-';

    $(p + 'dialog').one('shown.bs.modal', function() {
      // lazy-init editor
      CKEDITOR.replace(id + '-edit-body');
    }).on('show.bs.modal', function() {
      // reset close confirmation
      $(this).data('close-dialog-confirmed', false);

      // TODO load post
      $(p + 'name').val('');
      $(p + 'slug').val('');
    }).on('shown.bs.modal', function() {
      $(p + 'name').focus();
    }).on('hide.bs.modal', function() {
      return (
        $(this).data('close-dialog-confirmed') ||
        confirm('Close without saving changes?')
      );
    }).find('button[data-dismiss="modal"]').click(function() {
      // override close confirmation
      // FIXME: should this only be on save?
      $(p + 'dialog').data('close-dialog-confirmed', true);
    });

    $(p + 'confirm').click(function() {
      if ($(this).hasClass('disabled'))
        return false;

      // TODO: see #user-add-confirm
      alert('TODO: create');

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