Skip to content

Commit efc8dc9

Browse files
committed
hashset + input tracker + url schema added
hashset + input tracker + url schema added
1 parent c246aa9 commit efc8dc9

21 files changed

Lines changed: 705 additions & 100 deletions

JavaScript-Mvc-Framework/Areas/Admin/Controllers/NavItemsController.js

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,36 +13,105 @@
1313
/// <reference path="../../../app.run.js" />
1414
/// <reference path="../../../byId.js" />
1515
/// <reference path="D:\Working\GitHub\WereViewProject\WereViewApp\Content/Scripts/jquery-2.1.4.js" />
16+
/// <reference path="../../../extensions/inputChangeTracker.js" />
17+
/// <reference path="../../../ProtoType/Array.js" />
18+
/// <reference path="../../../extensions/spinner.js" />
1619

17-
$.app.controllers = $.app.controllers || {};
20+
;$.app.controllers = $.app.controllers || {};
1821
$.app.controllers.navItemsController = {
1922
// any thing related to controllers.
2023
pageId: "navitems-controller",
2124
$pageElement: null,
25+
prop: {
26+
/// populated from bindEvents.orderingTextBoxChange
27+
tracker: null,
28+
formId: "form-id-"
29+
},
30+
isDebugging: true,
2231
initialize: function () {
2332
var controllers = $.app.controllers,
2433
current = controllers.navItemsController;
2534
if (controllers.isCurrentPage(current)) {
2635
controllers.execute(current);
2736
}
2837
},
29-
isDebugging: true,
38+
getPage: function() {
39+
return $.app.controllers.navItemsController.$pageElement;
40+
},
41+
config : function() {
42+
43+
},
3044
actions: {
3145
/// <summary>
3246
/// Represents the collection of actions exist inside a controller.
3347
/// </summary>
34-
list: function () {
48+
list: function() {
3549
/// <summary>
36-
/// Represents index action page.
50+
/// Represents list action page.
3751
/// Refers to the data-action attribute.
3852
/// </summary>
3953
/// <returns type=""></returns>
40-
var self = $.app.controllers.navItemsControllerr,
41-
urlSchema = $.app.url.getGeneralUrlSchema(); // pass nothing will give add,edit,save,delete url
54+
var self = $.app.controllers.navItemsController,
55+
$page = self.getPage(),
56+
urlSchema = $.app.urls.getGeneralUrlSchema(false, ["SaveOrder"]); // pass nothing will give Create,Edit,Delete,Index url
4257
// urlSchema.edit will give edit url.
43-
// in the
58+
59+
60+
// create tracker
61+
var $allInputs = $(".ordering-textbox");
62+
self.prop.tracker = $.app.inputChangeTracker.createTracker($allInputs);
63+
64+
// bind events
65+
self.bindEvents.saveOrderButtonClick(urlSchema.SaveOrder);
66+
67+
68+
4469
console.log(urlSchema);
4570
}
71+
},
72+
73+
bindEvents: {
74+
saveOrderButtonClick: function(saveingUrl) {
75+
var $saveBtn = $.byId("save-order-btn");
76+
var self = $.app.controllers.navItemsController,
77+
$page = self.getPage(),
78+
prop = self.prop,
79+
tracker = prop.tracker,
80+
formIdFormat = prop.formId;
81+
82+
var getFormsData = function (ids, formIdFormat) {
83+
var formArray = new Array(ids.length);
84+
for (var i = 0; i < ids.length; i++) {
85+
var id = ids[i],
86+
$form = $.byId(formIdFormat + id);
87+
formArray[i] = $form.serializeArray();
88+
}
89+
return formArray;
90+
}
91+
$saveBtn.click(function(e) {
92+
e.preventDefault();
93+
// changed inputs ids array, only contains id values.
94+
var idsArray = tracker.getChangedInputsAttrArray("data-id");
95+
var data = getFormsData(idsArray, formIdFormat);
96+
var isInTestingMode = true;
97+
jQuery.ajax({
98+
method: "POST", // by default "GET"
99+
url: saveingUrl,
100+
data: data, // PlainObject or String or Array
101+
dataType: "JSON" //, // "Text" , "HTML", "xml", "script"
102+
}).done(function (response) {
103+
if (isInTestingMode) {
104+
console.log(response);
105+
}
106+
}).fail(function (jqXHR, textStatus, exceptionMessage) {
107+
console.log("Request failed: " + exceptionMessage);
108+
}).always(function () {
109+
console.log("complete");
110+
});
111+
console.log(idsArray);
112+
console.log(data);
113+
});
114+
}
46115
}
47116

48117
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
Array.prototype.isEqual = function (array) {
2+
/// <summary>
3+
/// Returns bool based on if both array contains same items.
4+
/// </summary>
5+
/// <param name="array" type="type">Array list</param>
6+
/// <returns type="">Returns true/false based if both of those array are same or not. If not same then false. If both empty then also return true.</returns>
7+
"use strict";
8+
9+
var isEmpty = this.length === 0;
10+
var arrayIsEmpty = array === undefined || array === null || array.length === 0;
11+
if (isEmpty === arrayIsEmpty && isEmpty === true) {
12+
return true;
13+
} else {
14+
if (this.length !== array.length) {
15+
return false;
16+
} else {
17+
// length is same , now loop through
18+
for (var i = 0; i < this.length; i++) {
19+
if (this[i] !== array[i]) {
20+
return false;
21+
}
22+
}
23+
return true; // both arrays are same.
24+
}
25+
}
26+
};
27+
28+
Array.prototype.getDifferentIndexes = function (array) {
29+
/// <summary>
30+
/// Returns array of indexes which are different between two arrays.
31+
/// </summary>
32+
/// <param name="array" type="type">Must pass same length array. Otherwise exception will be thrown.</param>
33+
/// <returns type="">Return an array of indexes which are different between two arrays</returns>
34+
"use strict";
35+
var isEmpty = this.length === 0;
36+
var arrayIsEmpty = array === undefined || array === null || array.length === 0;
37+
if (isEmpty === arrayIsEmpty && isEmpty !== false) {
38+
return [];
39+
} else {
40+
var results = [];
41+
if (this.length !== array.length) {
42+
throw new Error("Array indexes are not same.");
43+
} else {
44+
// length is same , now loop through
45+
for (var i = 0; i < this.length; i++) {
46+
if (this[i] !== array[i]) {
47+
results.push(i);
48+
}
49+
}
50+
return results;
51+
}
52+
}
53+
};
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1-
$.app.config = {
1+
; $.app = $.app || {};
2+
; $.app.config = {
23
/**
34
* app configuration settings.
45
* Runs before initializing everything.
56
*
67
*/
7-
setup : function() {
8+
setup: function() {
89
/// <summary>
910
/// Setup all configuration.
1011
/// </summary>
1112

1213
}
13-
}
14+
};
Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
$.app.global = {
1+
; $.app = $.app || {};
2+
$.app.global = {
23
/**
34
* global methods collection
45
* execute methods as per necessary, these methods will not run automatically.
56
*/
6-
}
7+
8+
};

JavaScript-Mvc-Framework/app.initializeMethods.js

Lines changed: 159 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
$.app.initializeMethods = {
1+
; $.app = $.app || {};
2+
$.app.initializeMethods = {
23
/**
34
* runs all the methods after initialize method.
45
*/
@@ -14,5 +15,161 @@
1415
$.executeFunction(functionsOrMethods);
1516
}
1617
}
18+
},
19+
toasterComponentSetup: function () {
20+
if (!$.isEmpty(toastr)) {
21+
toastr.options = {
22+
"closeButton": false,
23+
"debug": false,
24+
"newestOnTop": true,
25+
"progressBar": true,
26+
"positionClass": "toast-bottom-left",
27+
"preventDuplicates": true,
28+
"showDuration": "300",
29+
"hideDuration": "1000",
30+
"timeOut": "5000",
31+
"extendedTimeOut": "1000",
32+
"showEasing": "swing",
33+
"hideEasing": "linear",
34+
"showMethod": "fadeIn",
35+
"hideMethod": "fadeOut"
36+
}
37+
}
38+
},
39+
toolTipShow: function () {
40+
var $tooltipItems = $('.tooltip-show');
41+
if ($tooltipItems.length > 0) {
42+
$tooltipItems.tooltip({ container: 'body' });
43+
}
44+
45+
},
46+
seoHide: function () {
47+
var $seoHideItems = $(".seo-hide");
48+
if ($seoHideItems.length > 0) {
49+
$seoHideItems.hide();
50+
}
51+
},
52+
menuEnable: function () {
53+
$().jetmenu();
54+
var menuPage = $("#menu-item-edit-page");
55+
if (menuPage.length > 0) {
56+
var div = $("#hasDropdownDiv");
57+
div.hide();
58+
$("#HasDropDown").click(function () {
59+
if (this.checked) {
60+
div.show('slow');
61+
} else {
62+
div.hide('slow');
63+
}
64+
});
65+
}
66+
},
67+
bootstrapTableComponentEnable: function () {
68+
var $tables = $("table.bootstrap-table-do");
69+
if ($tables.length > 0) {
70+
$tables.bootstrapTable();
71+
}
72+
},
73+
datePickerComponentEnable: function () {
74+
if ($.isFunc($.datetimepicker)) {
75+
$(".datetimepicker-start").datetimepicker({
76+
pickDate: true, //en/disables the date picker
77+
pickTime: true, //en/disables the time picker
78+
useMinutes: true, //en/disables the minutes picker
79+
useSeconds: true, //en/disables the seconds picker
80+
useCurrent: true, //when true, picker will set the value to the current date/time
81+
minuteStepping: 1, //set the minute stepping
82+
defaultDate: "", //sets a default date, accepts js dates, strings and moment objects
83+
disabledDates: [], //an array of dates that cannot be selected
84+
enabledDates: [], //an array of dates that can be selected
85+
sideBySide: true //show the date and time picker side by side
86+
87+
});
88+
89+
$(".datepicker-start").datetimepicker({
90+
pickDate: true, //en/disables the date picker
91+
pickTime: false, //en/disables the time picker
92+
useMinutes: false, //en/disables the minutes picker
93+
useSeconds: false, //en/disables the seconds picker
94+
useCurrent: true, //when true, picker will set the value to the current date/time
95+
minuteStepping: 1, //set the minute stepping
96+
defaultDate: "", //sets a default date, accepts js dates, strings and moment objects
97+
disabledDates: [], //an array of dates that cannot be selected
98+
enabledDates: [], //an array of dates that can be selected
99+
sideBySide: true //show the date and time picker side by side
100+
});
101+
}
102+
},
103+
tagComponentEnable: function () {
104+
var $processForm = $.byId("server-validation-form");
105+
if ($processForm.length > 0) {
106+
var $createdTags = $(".tag-inputs");
107+
if ($createdTags.length > 0) {
108+
var $tokenField = $processForm.find("[name='__RequestVerificationToken']"),
109+
token = $tokenField.val();
110+
for (var i = 0; i < $createdTags.length; i++) {
111+
var $tagsInput = $($createdTags[0]),
112+
urlToPost = $tagsInput.attr("data-url");
113+
//
114+
$tagsInput.tagsinput({
115+
freeInput: true,
116+
trimValue: true,
117+
typeahead: {
118+
source: function (query) {
119+
return $.post(urlToPost, { id: query, __RequestVerificationToken: token }).done(function (response) {
120+
//console.log("tags:");
121+
//console.log("response:");
122+
//console.log(response);
123+
});
124+
}
125+
},
126+
onTagExists: function (item, $tag) {
127+
if ($.isEmpty($tag)) {
128+
$tag.hide.fadeIn();
129+
}
130+
}
131+
});
132+
}
133+
}
134+
135+
}
136+
},
137+
transactionStatusEnable: function () {
138+
var $transaction = $.byId("transaction-container"),
139+
hideTimeOut = parseInt($transaction.attr("data-hide-duration"));
140+
141+
var hideStatus = function () {
142+
$transaction.attr("data-shown", "true");
143+
$transaction.hide(500);
144+
};
145+
var timer = setTimeout(hideStatus, hideTimeOut);
146+
147+
var stopTimer = function () {
148+
clearTimeout(timer);
149+
}
150+
151+
$transaction.click(function () {
152+
stopTimer();
153+
hideStatus();
154+
});
155+
},
156+
loadWow: function () {
157+
//var options = {
158+
// scaleColor: false,
159+
// trackColor: 'rgba(266,144,0,0.0)',
160+
// barColor: '#ff7200',
161+
// lineWidth: 2,
162+
// lineCap: 'butt',
163+
// size: 253
164+
//};
165+
166+
167+
var wow = new WOW({
168+
boxClass: 'wow', // animated element css class (default is wow)
169+
animateClass: 'animated', // animation css class (default is animated)
170+
offset: 100, // distance to the element when triggering the animation (default is 0)
171+
mobile: false // trigger animations on mobile devices (true is default)
172+
});
173+
wow.init();
17174
}
18-
}
175+
};

0 commit comments

Comments
 (0)