aboutsummaryrefslogtreecommitdiff
path: root/data/stuff/test/tab-posts.js
blob: b9692a55ea587e889ec7812bd948e982373fe333 (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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>",
    ],
  });


  var POST_TYPES = {
    type: {
      last: false,
      name: "Type",
    },

    blog: {
      last: true,
      name: "Blog Post",

      cbs: {
        show: function() {
          $('#post-new-blog-name').val('');
          $('#post-new-blog-slug').val('');
          $('#post-new-blog-body').val('');
        },

        shown: function() {
          $('#post-new-blog-name').focus();
        },
      },
    },

    page: {
      last: true,
      name: "Page",
    },

    project: {
      last: true,
      name: "Project",
    },
  };

  $('#post-new-dialog').on('show.bs.modal', function() {
    $('#post-new-type-blog').click();

    $('#post-new-tab-type').parent().removeClass('active')
    $('#post-new-tab-type').click();
  });

  $.each(POST_TYPES, function(id, data) {
    $('#post-new-tab-' + id).on('show.bs.tab', function() {
      // update buttons
      $('#post-new-back').toggleClass('disabled', !data.last);
      $('#post-new-next').toggleClass('hidden', data.last);
      $('#post-new-confirm').toggleClass('hidden', !data.last)
        .find('span.name').text(data.name);
    });
    
    if (data.cbs) {
      // add event handlers
      $.each(data.cbs, function(ev_id, fn) {
        $('#post-new-tab-' + id).on(ev_id + '.bs.tab', fn);
      });
    }
  });

  $('#post-new-back').click(function() {
    $('#post-new-tab-type').click();

    // stop event
    return false;
  });

  $('#post-new-next').click(function() {
    $.each(POST_TYPES, function(id, data) {
      if ($('#post-new-type-' + id).is(':checked')) {
        // select tab
        $('#post-new-tab-' + id).click();

        return false;
      }
    });

    // stop event
    return false;
  });

  $('#post-new-confirm').click(function() {
    if (me.hasClass('disabled'))
      return false;

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

    // stop event
    return false;
  });

  $('#post-new-tab-pane-type label').dblclick(function() {
    $(this).find('input[type="radio"]').prop('checked', true);
    $('#post-new-next').click();

    // stop event
    return false;
  });

  $('#post-new-tab-blog').one('shown.bs.tab', function() {
    // lazy-init editor
    console.log('initializing editor');
/* 
 *     tinymce.init({
 *       selector: '#post-new-blog-body',
 *       plugins: 'fullscreen',
 *     });
 */ 
    CKEDITOR.replace('post-new-blog-body');
  });
});