c2 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/public/images/c2/alert-overlay.png +0 -0
  2. data/public/images/c2/back-light.png +0 -0
  3. data/public/images/c2/bg-body.png +0 -0
  4. data/public/images/c2/bg-header.png +0 -0
  5. data/public/images/c2/categories-small.png +0 -0
  6. data/public/images/c2/down-arrow.png +0 -0
  7. data/public/images/c2/entries-small.png +0 -0
  8. data/public/images/c2/external-link.png +0 -0
  9. data/public/images/c2/eye.png +0 -0
  10. data/public/images/c2/loading.gif +0 -0
  11. data/public/images/c2/new-category.png +0 -0
  12. data/public/images/c2/new-entry.png +0 -0
  13. data/public/images/c2/new-section.png +0 -0
  14. data/public/images/c2/ops.png +0 -0
  15. data/public/images/c2/trashcan.png +0 -0
  16. data/public/javascripts/c2/informant/application.js +35 -0
  17. data/public/javascripts/c2/informant/collections/buckets.js +9 -0
  18. data/public/javascripts/c2/informant/collections/entries.js +18 -0
  19. data/public/javascripts/c2/informant/collections/locus.js +6 -0
  20. data/public/javascripts/c2/informant/controllers/app.js +44 -0
  21. data/public/javascripts/c2/informant/init.js +42 -0
  22. data/public/javascripts/c2/informant/models/bucket.js +16 -0
  23. data/public/javascripts/c2/informant/models/entry.js +38 -0
  24. data/public/javascripts/c2/informant/models/locus.js +22 -0
  25. data/public/javascripts/c2/informant/views/entries/edit.js +84 -0
  26. data/public/javascripts/c2/informant/views/entries/index.js +23 -0
  27. data/public/javascripts/c2/informant/views/notice.js +33 -0
  28. data/public/javascripts/c2/informant/views/sidebar.js +27 -0
  29. data/public/javascripts/c2/lib/Sexy.min.js +16 -0
  30. data/public/javascripts/c2/lib/backbone-min.js +27 -0
  31. data/public/javascripts/c2/lib/jquery.Sexy.min.js +9 -0
  32. data/public/javascripts/c2/lib/jquery.activity-indicator-1.0.0.min.js +10 -0
  33. data/public/javascripts/c2/lib/jquery.ba-dotimeout.min.js +9 -0
  34. data/public/javascripts/c2/lib/jquery.dform-0.1.2.min.js +15 -0
  35. data/public/javascripts/c2/lib/jquery.min.js +16 -0
  36. data/public/javascripts/c2/lib/jquery.timeago.js +147 -0
  37. data/public/javascripts/c2/lib/pure_min.js +33 -0
  38. data/public/javascripts/c2/lib/underscore.min.js +25 -0
  39. data/public/stylesheets/c2.css +1045 -0
  40. metadata +42 -3
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,35 @@
1
+ var Informant = {
2
+ init: function() {
3
+ Informant.loadTemplates();
4
+ Informant.App = new Informant.AppController();
5
+ Backbone.history.start();
6
+ },
7
+ JST: {},
8
+ loadTemplates: function() {
9
+ $('[type="text/js-template"]').each(function() {
10
+ Informant.JST[$(this).data('template')] = _.template($(this).html());
11
+ });
12
+ }
13
+ };
14
+
15
+ var Locus = {
16
+ label: 'Users',
17
+ path: 'users',
18
+ scopes: 'ScopeList',
19
+ attributes: 'AttributeList'
20
+ };
21
+
22
+ var Attribute = {
23
+ label: 'fu',
24
+ template: 'string'
25
+ };
26
+
27
+ var Scope = {
28
+ label: 'Active',
29
+ path: 'active',
30
+ entries: 'EntryList'
31
+ };
32
+
33
+ var Entry = {
34
+ fu: 'bar',
35
+ };
@@ -0,0 +1,9 @@
1
+ Informant.BucketList = Backbone.Collection.extend({
2
+ model: Informant.BucketModel,
3
+ url: function() {
4
+ return this.parent.url() + '/buckets';
5
+ },
6
+ initialize: function(buckets, options) {
7
+ this.parent = options.parent;
8
+ },
9
+ });
@@ -0,0 +1,18 @@
1
+ Informant.EntryList = Backbone.Collection.extend({
2
+ model: Informant.EntryModel,
3
+ url: function() {
4
+ return this.parent.url() + '/entries';
5
+ },
6
+ initialize: function(buckets, options) {
7
+ this.parent = options.parent;
8
+ },
9
+ locus: function() {
10
+ return this.parent.locus();
11
+ },
12
+ path: function() {
13
+ return this.parent.entries_path();
14
+ },
15
+ newPath: function() {
16
+ return this.locus().entries_path() + '/new';
17
+ }
18
+ });
@@ -0,0 +1,6 @@
1
+ Informant.LocusList = Backbone.Collection.extend({
2
+ model: Informant.LocusModel,
3
+ initialize: function() {
4
+ this.url = '/c2/informant/locus';
5
+ }
6
+ });
@@ -0,0 +1,44 @@
1
+ Informant.AppController = Backbone.Controller.extend({
2
+ routes: {
3
+ "/": "root",
4
+ "/locus/:locusId/entries": "entryIndex",
5
+ "/locus/:locusId/entries/new": "entryNew",
6
+ "/locus/:locusId/entries/:entryId/edit": "entryEdit",
7
+ "/locus/:locusId/buckets/:bucketId/entries": "entryIndex"
8
+ },
9
+
10
+ initialize: function(options) {
11
+ this._current_nav_link = window.location.hash;
12
+ this._locus = new Informant.LocusList();
13
+ this._sidebar = new Informant.SidebarView({ collection: this._locus });
14
+ this._entryIndex = new Informant.EntryIndexView();
15
+ this._locus.fetch();
16
+ },
17
+
18
+ root: function() {
19
+ },
20
+
21
+ entryIndex: function(locusId,bucketId) {
22
+ var locus = this._locus.get(locusId);
23
+ if ( bucketId ) {
24
+ var bucket = locus.buckets.get(bucketId);
25
+ }
26
+ var entries = (bucket || locus).entries
27
+
28
+ this._current_nav_link = entries.path();
29
+ this._entryIndex.render(entries);
30
+ },
31
+
32
+ entryNew: function(locusId) {
33
+ var locus = this._locus.get(locusId);
34
+ var entry = locus.entries.add().last();
35
+ new Informant.EntryEditView({ model: entry });
36
+ },
37
+
38
+ entryEdit: function(locusId,entryId) {
39
+ var locus = this._locus.get(locusId);
40
+ var entry = locus.entries.get(entryId);
41
+ new Informant.EntryEditView({ model: entry });
42
+ }
43
+
44
+ });
@@ -0,0 +1,42 @@
1
+ var lib_dir = '/javascripts/c2/lib/';
2
+ var app_dir = '/javascripts/c2/informant/';
3
+
4
+ Sexy
5
+ .js(lib_dir + 'jquery.min.js')
6
+ .js(lib_dir + 'underscore.min.js')
7
+ .js(lib_dir + 'backbone-min.js')
8
+ .js(lib_dir + 'jquery.ba-dotimeout.min.js')
9
+ .js(lib_dir + 'jquery.timeago.js')
10
+ .js(lib_dir + 'jquery.activity-indicator-1.0.0.min.js')
11
+ .js(lib_dir + 'jquery.dform-0.1.2.min.js')
12
+ .js(app_dir + 'application.js')
13
+ .js(app_dir + 'views/notice.js')
14
+ .js(app_dir + 'views/sidebar.js')
15
+ .js(app_dir + 'views/entries/index.js')
16
+ .js(app_dir + 'views/entries/edit.js')
17
+ .js(app_dir + 'controllers/app.js')
18
+ .js(app_dir + 'models/locus.js')
19
+ .js(app_dir + 'models/bucket.js')
20
+ .js(app_dir + 'models/entry.js')
21
+ .js(app_dir + 'collections/locus.js')
22
+ .js(app_dir + 'collections/buckets.js')
23
+ .js(app_dir + 'collections/entries.js', function() {
24
+ $(function() {
25
+ window.location.hash = '/';
26
+
27
+ // Get a Backbone
28
+ Informant.init();
29
+
30
+ $('.flip-trigger').bind('click', function() {
31
+ $('#app').toggleClass('flip');
32
+ });
33
+
34
+ // Triggers
35
+ $('.dropdown-trigger').bind('click', function() {
36
+ $(this).parent().toggleClass('active');
37
+ });
38
+ });
39
+ });
40
+
41
+
42
+
@@ -0,0 +1,16 @@
1
+ Informant.BucketModel = Backbone.Model.extend({
2
+ initialize: function(options) {
3
+ this.id = options._id;
4
+ this.entries = new Informant.EntryList(options.entries_page, { parent: this, cached: false });
5
+ },
6
+
7
+ locus: function() {
8
+ return this.collection.parent;
9
+ },
10
+
11
+ entries_path: function() {
12
+ return '#/locus/' + this.locus().id + '/buckets/' + this.id + '/entries';
13
+ },
14
+
15
+ index_label: function() { return this.escape('label'); }
16
+ });
@@ -0,0 +1,38 @@
1
+ Informant.EntryModel = Backbone.Model.extend({
2
+ initialize: function(options) {
3
+ this.id = (options._id || options.id);
4
+ // this.bind('save', Informant.App._locus.fetch());
5
+ },
6
+
7
+ locus: function() {
8
+ return this.collection.locus();
9
+ },
10
+
11
+ label: function() {
12
+ return this.get(this.locus().escape('entry_label'));
13
+ },
14
+
15
+ form: function() {
16
+ var that = this;
17
+ var form = that.locus().get('entry_form_builder');
18
+ var fields = _(form.elements).map(function(element) {
19
+ return (element.id == 'entry-fields') ? element : null ;
20
+ });
21
+
22
+ fields = _(fields).compact()[0];
23
+ fields = _(fields.elements).map(function(element) {
24
+ return _(element.elements).select(function(e) { return e['class'] != 'tip'; })[0];
25
+ });
26
+ _(fields).each(function(field, index, list) {
27
+ if (field.type == 'checkbox') { field.checked = that.get(field.name) }
28
+ else { field.value = that.get(field.name); }
29
+ });
30
+ form.action = '#';
31
+ return form;
32
+ },
33
+
34
+ hash_path: function() {
35
+ return this.locus().hash_path() + '/entries/' + this.id;
36
+ }
37
+
38
+ });
@@ -0,0 +1,22 @@
1
+ Informant.LocusModel = Backbone.Model.extend({
2
+ initialize: function(options) {
3
+ this.id = options._id;
4
+ this.buckets = new Informant.BucketList(options.buckets, { parent: this });
5
+ this.entries = new Informant.EntryList(options.entries_page, { parent: this, cached: false });
6
+ },
7
+
8
+ locus: function() {
9
+ return this;
10
+ },
11
+
12
+ index_label: function() { return 'All'; },
13
+
14
+ entries_path: function() {
15
+ return this.hash_path() + '/entries';
16
+ },
17
+
18
+ hash_path: function() {
19
+ return '#/locus/' + this.locus().id;
20
+ }
21
+
22
+ });
@@ -0,0 +1,84 @@
1
+ Informant.EntryEditView = Backbone.View.extend({
2
+ el: $('#app-back'),
3
+
4
+ events: {
5
+ 'submit #entry': 'save',
6
+ 'click .flip-trigger': 'flip'
7
+ },
8
+
9
+ initialize: function() {
10
+ this.render();
11
+ },
12
+
13
+ render: function() {
14
+ if(this.model.isNew()) {
15
+ this.$('.content .header h1 .type').html('New');
16
+ this.$('.content .header h1 strong').html(this.model.locus().get('singular_label'));
17
+ } else {
18
+ this.$('.content .header h1 .type').html('Editing ' + this.model.locus().get('singular_label'));
19
+ this.$('.content .header h1 strong').html(this.model.label());
20
+ }
21
+
22
+ this.$('#entry').empty().removeClass().buildForm(this.model.form());
23
+
24
+ this.$('abbr.timeago').timeago();
25
+ $('#app').addClass('flip');
26
+
27
+ return this;
28
+ },
29
+
30
+ save: function() {
31
+ var self = this;
32
+ var msg = this.model.isNew() ? 'Entry Successfully Created!' : "Entry Saved!";
33
+ var fields = _(this.$('#entry').serializeArray()).reduce( function(memo, field) {
34
+ memo[field.name] = field.value;
35
+ return memo;
36
+ }, {});
37
+
38
+ this.$('#entry-fields input:checkbox').each(function() {
39
+ fields[$(this).attr('name')] = $(this).is(':checked');
40
+ });
41
+
42
+ this.el.activity();
43
+
44
+ this.model.save(fields, {
45
+ success: function(model, response) {
46
+ if (_.isEmpty(response.errors)) {
47
+ new Informant.NoticeView({ message: msg });
48
+ self.clearErrors();
49
+ Informant.App._locus.fetch();
50
+ } else {
51
+ new Informant.ErrorView();
52
+ self.addErrors(response.errors);
53
+ }
54
+
55
+ self.el.activity(false);
56
+ },
57
+ error: function(model, response) {
58
+ new Informant.ErrorView();
59
+ self.el.activity(false);
60
+ }
61
+ });
62
+
63
+ return false;
64
+ },
65
+
66
+ flip: function() { $('#app').toggleClass('flip'); },
67
+
68
+ addErrors: function(errors) {
69
+ console.log(errors);
70
+ this.clearErrors();
71
+ _(errors).each(function(msg, field) {
72
+ container = $('#entry_' + field + '_field');
73
+ container.addClass('field_with_errors');
74
+ container.find('label').append('<span class="error">' + msg.join(' & ') + '</span>');
75
+ });
76
+ },
77
+
78
+ clearErrors: function() {
79
+ $('.field_with_errors span.error').remove();
80
+ $('.field_with_errors').removeClass('.field_with_errors');
81
+ }
82
+
83
+
84
+ });
@@ -0,0 +1,23 @@
1
+ Informant.EntryIndexView = Backbone.View.extend({
2
+ el: $('#app-front'),
3
+
4
+ initialize: function(options) {
5
+ },
6
+
7
+ render: function(entries) {
8
+ var that = this;
9
+ that.el.empty();
10
+ that.el.html(Informant.JST.entryIndex({entries: entries}));
11
+ $('#aside').html(Informant.JST.entryIndexAside({entries: entries}));
12
+
13
+ $('.flip-trigger').bind('click', function() {
14
+ $('#app').toggleClass('flip');
15
+ });
16
+
17
+ $('abbr.timeago').timeago();
18
+
19
+ $('#app').removeClass('flip');
20
+
21
+ return this;
22
+ }
23
+ });
@@ -0,0 +1,33 @@
1
+ Informant.NoticeView = Backbone.View.extend({
2
+ className: "success",
3
+ displayLength: 5000,
4
+ defaultMessage: '',
5
+
6
+ initialize: function() {
7
+ _.bindAll(this, 'render');
8
+ this.message = this.options.message || this.defaultMessage;
9
+ this.render();
10
+ },
11
+
12
+ render: function() {
13
+ var view = this;
14
+
15
+ $(this.el).html(this.message);
16
+ $(this.el).hide();
17
+ $('#notices').html(this.el);
18
+ $(this.el).slideDown();
19
+ $.doTimeout(this.displayLength, function() {
20
+ $(view.el).slideUp();
21
+ $.doTimeout(2000, function() {
22
+ view.remove();
23
+ });
24
+ });
25
+
26
+ return this;
27
+ }
28
+ });
29
+
30
+ Informant.ErrorView = Informant.NoticeView.extend({
31
+ className: "error",
32
+ defaultMessage: 'Uh oh! Something went wrong. Please try again.'
33
+ });
@@ -0,0 +1,27 @@
1
+ Informant.SidebarView = Backbone.View.extend({
2
+ el: $('#sidebar'),
3
+ initialize: function(options) {
4
+ _.bindAll(this, 'render');
5
+ this.collection.bind('refresh', this.render);
6
+
7
+ this.el.activity();
8
+ },
9
+
10
+ render: function() {
11
+ this.el.activity();
12
+ this.el.empty();
13
+ this.el.html(Informant.JST.sidebar({collection: this.collection}));
14
+
15
+ this.$('.current').removeClass('current');
16
+ this.$('a[href="' + Informant.App._current_nav_link + '"]').parent().addClass('current');
17
+
18
+ this.el.activity(false);
19
+
20
+ $('.sitemap a').bind('click', function() {
21
+ $('.sitemap .current').removeClass('current');
22
+ $(this).parent().addClass('current');
23
+ });
24
+
25
+ return this;
26
+ }
27
+ });