admin_data 1.1.6 → 1.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (32) hide show
  1. data/lib/admin_data.rb +1 -1
  2. data/lib/admin_data/version.rb +1 -1
  3. data/lib/public/images/add.png +0 -0
  4. data/lib/public/images/no.png +0 -0
  5. data/lib/public/images/site.png +0 -0
  6. data/lib/public/javascripts/advance_search/act_on_result.js +45 -0
  7. data/lib/public/javascripts/advance_search/advance_search.js +83 -0
  8. data/lib/public/javascripts/advance_search/advance_search_structure.js +79 -0
  9. data/lib/public/javascripts/advance_search/ajaxify_advance_search.js +28 -0
  10. data/lib/public/javascripts/advance_search/build_first_row.js +8 -0
  11. data/lib/public/javascripts/advance_search/event_bindings.js +76 -0
  12. data/lib/public/javascripts/advance_search/global_ajax_setting.js +10 -0
  13. data/lib/public/javascripts/advance_search/trigger_submit_on_domready.js +6 -0
  14. data/lib/public/javascripts/misc/drop_down_change.js +8 -0
  15. data/lib/public/javascripts/misc/js_util.js +58 -0
  16. data/lib/public/javascripts/misc/quick_search_input_focus.js +6 -0
  17. data/lib/public/javascripts/test/act_on_result.js +120 -0
  18. data/lib/public/javascripts/test/advance_search.js +80 -0
  19. data/lib/public/javascripts/test/ajaxify_advance_search.js +29 -0
  20. data/lib/public/javascripts/test/build_first_row.js +10 -0
  21. data/lib/public/javascripts/test/event_bindings.js +100 -0
  22. data/lib/public/javascripts/vendor/jack.js +903 -0
  23. data/lib/public/javascripts/vendor/jquery-1.4.2.js +6240 -0
  24. data/lib/public/javascripts/vendor/jquery-ui-1.7.2.custom.min.js +298 -0
  25. data/lib/public/javascripts/vendor/jquery.ba-isjquery.js +21 -0
  26. data/lib/public/javascripts/vendor/jquery_form.js +814 -0
  27. data/lib/public/javascripts/vendor/log.js +9 -0
  28. data/lib/public/javascripts/vendor/qunit.js +1043 -0
  29. data/lib/public/javascripts/vendor/rails.js +132 -0
  30. data/lib/public/stylesheets/base.css +1109 -0
  31. data/lib/public/stylesheets/vendor/jquery-ui-1.7.2.custom.css +406 -0
  32. metadata +32 -3
@@ -9,7 +9,7 @@ module AdminData
9
9
  end
10
10
 
11
11
  def self.public_dir
12
- File.expand_path(File.join(LIBPATH, '..', 'public')) + File::SEPARATOR
12
+ File.expand_path(File.join(LIBPATH, 'public')) + File::SEPARATOR
13
13
  end
14
14
 
15
15
  class << self
@@ -1,3 +1,3 @@
1
1
  module AdminData
2
- VERSION = '1.1.6'
2
+ VERSION = '1.1.7'
3
3
  end
Binary file
Binary file
@@ -0,0 +1,45 @@
1
+ var AdminData = AdminData || {};
2
+
3
+ AdminData.actOnResult = {
4
+
5
+ action: function(action_type) {
6
+ var formData = $('#advance_search_form').data('admin_data_form_array'),
7
+ parameterizedData;
8
+
9
+ formData.push({
10
+ 'name': 'admin_data_advance_search_action_type',
11
+ 'value': action_type
12
+ });
13
+
14
+ parameterizedData = $.param(formData);
15
+
16
+ $.ajax({
17
+ url: $('#advance_search_form').attr('action'),
18
+ type: 'post',
19
+ dataType: 'json',
20
+ data: parameterizedData,
21
+ success: function(json) {
22
+ AdminData.actOnResult.successCallback(json);
23
+ }
24
+ });
25
+ },
26
+
27
+ successCallback: function(json) {
28
+ $('#results').text(json.success);
29
+ }
30
+
31
+ };
32
+
33
+ $('#advance_search_delete_all').live('click', function() {
34
+ if (window.confirm('Are you sure?')) {
35
+ AdminData.actOnResult.action('delete');
36
+ }
37
+ return false;
38
+ });
39
+
40
+ $('#advance_search_destroy_all').live('click', function() {
41
+ if (window.confirm('Are you sure?')) {
42
+ AdminData.actOnResult.action('destroy');
43
+ }
44
+ return false;
45
+ });
@@ -0,0 +1,83 @@
1
+ var AdminData = AdminData || {};
2
+
3
+ AdminData.advanceSearch = {
4
+
5
+ buildFirstRow: function() {
6
+
7
+ var img = $('<img />', {
8
+ src: '/admin_data/public/images/add.png'
9
+ });
10
+
11
+ $('#advance_search_table').append(this.buildRow())
12
+ .find('tr td:last a')
13
+ .attr('id','add_row_link_1')
14
+ .removeClass('remove_row')
15
+ .addClass('add_row_link')
16
+ .html('')
17
+ .append(img);
18
+ },
19
+
20
+ buildCol1: function() {
21
+ var i, col = $('<select />', { className: 'col1' }).append($('<option />')),
22
+ tableStructure = $('#advance_search_table').data('table_structure');
23
+
24
+ for (i in tableStructure) {
25
+ $('<option />', {
26
+ text: i,
27
+ value: i
28
+ }).appendTo(col);
29
+ }
30
+ return $('<td />').append(col);
31
+ },
32
+
33
+ buildCol2: function() {
34
+ var select = $('<select />', { className: 'col2', disabled: 'disabled' });
35
+ return $('<td />').append(select);
36
+ },
37
+
38
+ buildCol3: function() {
39
+ var select = $('<input />', { className: 'col3' });
40
+ return $('<td />').append($('<input />', { className: 'col3', disabled: 'disabled' }));
41
+ },
42
+
43
+ buildCol4: function() {
44
+ var img = $('<img />', {
45
+ src: '/admin_data/public/images/no.png'
46
+ });
47
+
48
+ return $('<td />').append($('<a />', {
49
+ text: '',
50
+ href: '#',
51
+ className: 'remove_row'
52
+ }).append(img));
53
+ },
54
+
55
+ buildRow: function() {
56
+
57
+ var $tr = $('<tr />'),
58
+ currentRowNumber = $(document).data('currentRowNumber'),
59
+ that = this,
60
+ build_array = ['buildCol1', 'buildCol2', 'buildCol3', 'buildCol4'];
61
+
62
+ if (currentRowNumber === undefined) {
63
+ currentRowNumber = 1;
64
+ $(document).data('currentRowNumber', currentRowNumber);
65
+ } else {
66
+ currentRowNumber = parseInt(currentRowNumber, 10) + 1;
67
+ $(document).data('currentRowNumber', currentRowNumber);
68
+ }
69
+
70
+ $.each(build_array, function(index, value) {
71
+ $tr.append(that[value]());
72
+ });
73
+
74
+ $tr.find('select.col1').attr({ name: 'adv_search[' + currentRowNumber + '_row][col1]' });
75
+ $tr.find('select.col2').attr({ name: 'adv_search[' + currentRowNumber + '_row][col2]' });
76
+ $tr.find('input.col3').attr({ name: 'adv_search[' + currentRowNumber + '_row][col3]' });
77
+
78
+ $tr.find('.remove_row').attr('id', 'remove_row_'+currentRowNumber);
79
+
80
+ return $tr;
81
+ }
82
+
83
+ };
@@ -0,0 +1,79 @@
1
+ AdminData = AdminData || {};
2
+
3
+ AdminData.mappings = {
4
+
5
+ //JSLint complains if a hash has key named boolean. So I am changing the key to booleant
6
+ booleant: {
7
+ options: [
8
+ ["is null", "is_null"],
9
+ ["is not null", "is_not_null"],
10
+ ["is true", "is_true"],
11
+ ["is false", "is_false"]
12
+ ]
13
+ },
14
+
15
+ string: {
16
+ options: [
17
+ ["is null", "is_null"],
18
+ ["is not null", "is_not_null"],
19
+ ["contains", "contains"],
20
+ ["is exactly", "is_exactly"],
21
+ ["doesn't contain", "does_not_contain"]
22
+ ]
23
+ },
24
+
25
+ text: {
26
+ options: [
27
+ ["is null", "is_null"],
28
+ ["is not null", "is_not_null"],
29
+ ["Contains", "contains"],
30
+ ["Doesn't Contain", "does_not_contain"]
31
+ ]
32
+ },
33
+
34
+ datetime: {
35
+ options: [
36
+ ["is null", "is_null"],
37
+ ["is not null", "is_not_null"],
38
+ ['on', "is_on"],
39
+ ['on or before', "is_on_or_before_date"],
40
+ ['on or after', "is_on_or_after_date"]
41
+ ]
42
+ },
43
+
44
+ date: {
45
+ options: [
46
+ ["is null", "is_null"],
47
+ ["is not null", "is_not_null"],
48
+ ['on', "is_on"],
49
+ ['on or before', "is_on_or_before_date"],
50
+ ['on or after', "is_on_or_after_date"]
51
+ ]
52
+ },
53
+
54
+ time: {
55
+ options: [
56
+ ["is null", "is_null"],
57
+ ["is not null", "is_not_null"],
58
+ ["is exactly", "is_exactly"]
59
+ ]
60
+ },
61
+
62
+ decimal: {
63
+ options: [
64
+ ['is equal to', "is_equal_to"],
65
+ ['is less than', "less_than"],
66
+ ['is greater than', "greater_than"]
67
+ ]
68
+ },
69
+
70
+ integer: {
71
+ options: [
72
+ ['is equal to', "is_equal_to"],
73
+ ['is less than', "less_than"],
74
+ ['is greater than', "greater_than"]
75
+ ]
76
+ }
77
+ };
78
+
79
+
@@ -0,0 +1,28 @@
1
+ var AdminData = AdminData || {};
2
+
3
+ AdminData.ajaxifyAdvanceSearch = {
4
+ successCallback: function(responseText) {
5
+ $('#results').html(responseText);
6
+ },
7
+
8
+ beforeSubmitCallback: function(formArray, jqForm) {
9
+ $('#results').html('<span class="searching_message">searching...</span>');
10
+ $('#advance_search_form').data('admin_data_form_array', formArray);
11
+ }
12
+ };
13
+
14
+ $(function() {
15
+
16
+ var options = {
17
+ success: function(responseText) {
18
+ AdminData.ajaxifyAdvanceSearch.successCallback(responseText);
19
+ },
20
+ beforeSubmit: function(formArray, jqForm) {
21
+ AdminData.ajaxifyAdvanceSearch.beforeSubmitCallback(formArray, jqForm);
22
+ }
23
+ };
24
+
25
+ $('#advance_search_form').ajaxForm(options);
26
+
27
+ });
28
+
@@ -0,0 +1,8 @@
1
+ $(function() {
2
+
3
+ var json = $.parseJSON( $('#primary_column_type_info').html());
4
+ $('#advance_search_table').data('table_structure', json);
5
+ AdminData.advanceSearch.buildFirstRow();
6
+
7
+ });
8
+
@@ -0,0 +1,76 @@
1
+ var AdminData = AdminData || {};
2
+
3
+ AdminData.bindings = {
4
+
5
+ col2_change: function(e) {
6
+ var arrayList = ['is_false', 'is_true', 'is_null', 'is_not_null'],
7
+ $col2 = $(e.target).closest('select'),
8
+ value = $col2.val(),
9
+ tableStructure = $('#advance_search_table').data('table_structure'),
10
+ $col3 = $col2.parents('tr').find('td input.col3'),
11
+ $col1 = $col2.parents('tr').find('td select.col1'),
12
+ col1ColumnType = tableStructure[$col1.val()];
13
+
14
+
15
+ if (value.length === 0 || ($.inArray(value, arrayList) > - 1)) {
16
+ $col3.val('').attr('disabled','disabled');
17
+
18
+ } else {
19
+ $col3.removeAttr('disabled');
20
+ if (col1ColumnType === 'datetime' || col1ColumnType === 'date') {
21
+ $col3.val(AdminData.jsUtil.dateToString(new Date())).addClass('datepicker');
22
+
23
+ $('.datepicker').datepicker({ dateFormat: 'dd-MM-yy', changeYear: true, changeMonth: true });
24
+
25
+ } else {
26
+ $('.datepicker').datepicker('destroy');
27
+ $col3.removeClass('datepicker').focus(); // do not create focus for date pickers
28
+ }
29
+ }
30
+ },
31
+
32
+ pagination_click: function(e) {
33
+ var href = $(e.target).closest('a').attr('href');
34
+
35
+ $.ajax({ url: href, dataType: "text", success: function(responseText){
36
+ $('#results').html(responseText);
37
+ }});
38
+
39
+ AdminData.jsUtil.colorizeRows();
40
+ },
41
+
42
+ col1_change: function(e) {
43
+ var col1 = $(e.target).closest('select'),
44
+ tableStructure = $('#advance_search_table').data('table_structure'),
45
+ columnType = tableStructure[col1.val()],
46
+ options = AdminData.mappings[columnType]['options'],
47
+ col2 = col1.parents('tr').find('td select.col2');
48
+
49
+ col2.html('');
50
+ AdminData.jsUtil.buildOptionsFromArray(options, col2);
51
+ col2.trigger('change').removeAttr('disabled');
52
+ }
53
+ };
54
+
55
+ $('.pagination a').live('click', function(e) {
56
+ AdminData.bindings.pagination_click(e);
57
+ return false;
58
+ });
59
+
60
+ $('#advance_search_table a.add_row_link').live('click', function() {
61
+ $('#advance_search_table').append(AdminData.advanceSearch.buildRow());
62
+ return false;
63
+ });
64
+
65
+ $('#advance_search_table a.remove_row').live('click', function(e) {
66
+ $(e.target).closest('tr').remove();
67
+ return false;
68
+ });
69
+
70
+ $('#advance_search_table select.col1').live('change', function(e) {
71
+ AdminData.bindings.col1_change(e);
72
+ });
73
+
74
+ $('#advance_search_table select.col2').live('change', function(e) {
75
+ AdminData.bindings.col2_change(e);
76
+ });
@@ -0,0 +1,10 @@
1
+ $(function() {
2
+
3
+ $.ajaxSetup({
4
+ 'beforeSend': function(xhr) {
5
+ xhr.setRequestHeader("Accept", "text/javascript");
6
+ }
7
+ });
8
+
9
+ });
10
+
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+
3
+ $('#advance_search_form').trigger('submit');
4
+
5
+ });
6
+
@@ -0,0 +1,8 @@
1
+ $(function() {
2
+
3
+ $('.drop_down_value_klass').change(function() {
4
+ window.location = $(this).val();
5
+ });
6
+
7
+ });
8
+
@@ -0,0 +1,58 @@
1
+ var AdminData = AdminData || {};
2
+
3
+ /**
4
+ * A general Utility
5
+ * @namespace AdminData
6
+ * @class jsUtil
7
+ */
8
+ AdminData.jsUtil = {
9
+
10
+ // TODO since advance search was not working with util confirm , window.confirm is used directly
11
+ // fix it later
12
+ confirm: function(arg) {
13
+ window.confirm(arg);
14
+ },
15
+
16
+ buildOptionsFromArray: function(array, element) {
17
+ element.append($('<option />'));
18
+ for (i in array) {
19
+ $('<option />').text(array[i][0]).attr('value', array[i][1]).appendTo(element);
20
+ }
21
+ element.attr('disabled', false);
22
+ },
23
+
24
+ colorizeRows: function() {
25
+ $('.colorize tr:odd').addClass('odd');
26
+ $('.colorize tr:even').addClass('even');
27
+ },
28
+
29
+ /**
30
+ * Returns the input date in string format.
31
+ *
32
+ * @param {date} input date
33
+ * @return {string} The string value of input date
34
+ */
35
+ dateToString: function(date) {
36
+ var month = (date.getMonth() + 1).toString();
37
+ var day = date.getDate().toString();
38
+ //days between 1 and 9 should have 0 before them
39
+ if (day.length == 1) day = '0' + day;
40
+ var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
41
+ return day + "-" + months[month - 1] + "-" + date.getFullYear();
42
+ },
43
+
44
+ /**
45
+ * Generate a random number between 1 and 10000000
46
+ *
47
+ * @return {Integer} a random Integer
48
+ *
49
+ */
50
+ randomNumber: function() {
51
+ var maxVal = 100000000,
52
+ minVal = 1;
53
+ var randVal = minVal + (Math.random() * (maxVal - minVal));
54
+ return Math.round(randVal);
55
+ }
56
+
57
+ };
58
+
@@ -0,0 +1,6 @@
1
+ $(function() {
2
+
3
+ $('#quick_search_input').focus();
4
+
5
+ });
6
+
@@ -0,0 +1,120 @@
1
+ module('act_on_result', {
2
+ teardown: function() {
3
+ $('#advance_search_delete_all').remove();
4
+ $('#advance_search_destroy_all').remove();
5
+ $('#results').remove();
6
+ $('#advance_search_form').remove();
7
+ },
8
+ setup: function() {
9
+ $(document.body).append($('<a />', {
10
+ href: '#',
11
+ id: 'advance_search_delete_all'
12
+ }));
13
+
14
+ $(document.body).append($('<a />', {
15
+ href: '#',
16
+ id: 'advance_search_destroy_all'
17
+ }));
18
+
19
+ $(document.body).append($('<div />', {
20
+ id: 'results'
21
+ }));
22
+
23
+ $(document.body).append($('<div />', {
24
+ id: 'advance_search_form'
25
+ }));
26
+ }
27
+ });
28
+
29
+ test('invoking success callback', function() {
30
+ expect(1);
31
+ AdminData.actOnResult.successCallback({
32
+ success: 'hello world'
33
+ });
34
+ equals('hello world', $('#results').text(), '#results should have text hello world');
35
+ });
36
+
37
+ test('live clicking #advance_search_delete_all with cancel action', function() {
38
+ expect(0);
39
+ jack(function() {
40
+ jack.expect('AdminData.jsUtil.confirm').once().mock(function() {
41
+ return false;
42
+ });
43
+ //TODO ensure that the value passed to action is delete
44
+ jack.expect('AdminData.actOnResult.action').exactly('0 time');
45
+ $('#advance_search_delete_all').trigger('click');
46
+ });
47
+ });
48
+
49
+ test('live clicking #advance_search_delete_all', function() {
50
+ expect(0);
51
+ var args;
52
+
53
+ jack(function() {
54
+ jack.expect('AdminData.jsUtil.confirm').once().mock(function() {
55
+ return true;
56
+ });
57
+ jack.expect('AdminData.actOnResult.action').once().mock(function(action_type) {
58
+ args = action_type;
59
+ return {};
60
+ });
61
+ $('#advance_search_delete_all').trigger('click');
62
+ });
63
+ equals('delete', args, 'action_type should be delete');
64
+
65
+ });
66
+
67
+ test('live clicking #advance_search_destroy_all with cancel action', function() {
68
+ expect(0);
69
+ jack(function() {
70
+ jack.expect('AdminData.jsUtil.confirm').once().mock(function() {
71
+ return false;
72
+ });
73
+ jack.expect('AdminData.actOnResult.action').exactly('0 time');
74
+ $('#advance_search_destroy_all').trigger('click');
75
+ });
76
+ });
77
+
78
+ test('live clicking #advance_search_destroy_all', function() {
79
+ expect(0);
80
+ var args;
81
+
82
+ jack(function() {
83
+ jack.expect('AdminData.jsUtil.confirm').once().mock(function() {
84
+ return true;
85
+ });
86
+ jack.expect('AdminData.actOnResult.action').once().mock(function(action_type) {
87
+ args = action_type;
88
+ return {};
89
+ });
90
+ $('#advance_search_destroy_all').trigger('click');
91
+ });
92
+ equals('destroy', args, 'action_type should be destroy');
93
+ });
94
+
95
+ test('actOnResultAJAX', function() {
96
+ expect(5);
97
+ $('#advance_search_form').attr('action', 'http://localhost:3000');
98
+ $('#advance_search_form').data('admin_data_form_array', [{
99
+ name: 'foo',
100
+ value: 'i_am_foo'
101
+ }]);
102
+
103
+ var ajaxArgs;
104
+
105
+ jack(function() {
106
+ jack.expect('$.ajax').once().mock(function(args) {
107
+ ajaxArgs = args;
108
+ });
109
+ AdminData.actOnResult.action('delete');
110
+ });
111
+
112
+ equals('post', ajaxArgs.type, 'ajax arguments should have type as post');
113
+ equals('json', ajaxArgs.dataType, 'ajax arguments should have json as dataType');
114
+ equals('http://localhost:3000', ajaxArgs.url, 'ajax arguments should have valid url');
115
+ var data = ajaxArgs.data;
116
+ ok(data, 'ajax arguments should have value for key data');
117
+ equals('foo=i_am_foo&admin_data_advance_search_action_type=delete', data, 'data should have parameterized value');
118
+
119
+ });
120
+