');
- $table.append($tr);
- }
-
- $td = $('');
- $td.data("day", realDay);
-
- $tr.append($td);
-
- if (firstWday > i) {/* Before months day */
- $td.text(beforeMonthLastDay + realDay);
- $td.addClass('day_another_month');
- $td.data("dateStr", dateBeforeMonth.getFullYear() + "/" + (dateBeforeMonth.getMonth() + 1) + "/" + (beforeMonthLastDay + realDay));
- realDayObj.setDate(beforeMonthLastDay + realDay);
- realDayObj.setMonth(dateBeforeMonth.getMonth() );
- realDayObj.setYear(dateBeforeMonth.getFullYear() );
- } else if (i < firstWday + lastDay) {/* Now months day */
- $td.text(realDay);
- $td.data("dateStr", (date.getFullYear()) + "/" + (date.getMonth() + 1) + "/" + realDay);
- realDayObj.setDate( realDay );
- realDayObj.setMonth( date.getMonth() );
- realDayObj.setYear( date.getFullYear() );
- } else {/* Next months day */
- $td.text(realDay - lastDay);
- $td.addClass('day_another_month');
- $td.data("dateStr", dateNextMonth.getFullYear() + "/" + (dateNextMonth.getMonth() + 1) + "/" + (realDay - lastDay));
- realDayObj.setDate( realDay - lastDay );
- realDayObj.setMonth( dateNextMonth.getMonth() );
- realDayObj.setYear( dateNextMonth.getFullYear() );
- }
-
- /* Check a wday */
- var wday = ((i + firstDayDiff) % 7);
- if(allowWdays != null) {
- if ($.inArray(wday, allowWdays) == -1) {
- $td.addClass('day_in_unallowed');
- continue; // Skip
- }
- } else if (wday === 0) {/* Sunday */
- $td.addClass('wday_sun');
- } else if (wday == 6) {/* Saturday */
- $td.addClass('wday_sat');
- }
-
- /* Set a special mark class */
- if (realDay == date.getDate()) { /* selected day */
- $td.addClass('active');
- }
-
- if (isCurrentMonth && realDay == todayDate.getDate()) { /* today */
- $td.addClass('today');
- }
-
- var realDayObjMN = new Date(realDayObj.getTime());
- realDayObjMN.setHours(23);
- realDayObjMN.setMinutes(59);
- realDayObjMN.setSeconds(59);
-
- if (
- // compare to 23:59:59 on the current day (if MIN is 1pm, then we still need to show this day
- ((minDate != null) && (minDate > realDayObjMN.getTime())) || ((maxDate != null) && (maxDate < realDayObj.getTime())) // compare to 00:00:00
- ) { // Out of range day
- $td.addClass('out_of_range');
- } else if (isFutureOnly && isPast) { // Past day
- $td.addClass('day_in_past');
- } else {
- /* Set event-handler to day cell */
- $td.click(function() {
- if ($(this).hasClass('hover')) {
- $(this).removeClass('hover');
- }
- $(this).addClass('active');
-
- var $picker = getParentPickerObject($(this));
- var targetDate = new Date($(this).data("dateStr"));
- var selectedDate = getPickedDate($picker);
- draw($picker, {
- "isAnim": false,
- "isOutputToInputObject": true
- }, targetDate.getFullYear(), targetDate.getMonth(), targetDate.getDate(), selectedDate.getHours(), selectedDate.getMinutes());
- if ($picker.data("dateOnly") === true && $picker.data("isInline") === false && $picker.data("closeOnSelected")){
- // Close a picker
- ActivePickerId = -1;
- $picker.hide();
- }
- });
-
- $td.hover(function() {
- if (! $(this).hasClass('active')) {
- $(this).addClass('hover');
- }
- }, function() {
- if ($(this).hasClass('hover')) {
- $(this).removeClass('hover');
- }
- });
- }
-
- /* ---- */
- }
-
- if ($picker.data("dateOnly") === true) {
- /* dateOnly mode */
- $timelist.css("display", "none");
- } else {
- /* Timelist ----- */
- $timelist.children().remove();
-
- /* Set height to Timelist (Calendar innerHeight - Calendar padding) */
- if ($calendar.innerHeight() > 0) {
- $timelist.css("height", $calendar.innerHeight() - 10 + 'px');
- }
-
- realDayObj = new Date(date.getTime());
- $timelist.css("height", $calendar.innerHeight() - 10 + 'px');
-
- /* Output time cells */
- var hour_ = minTime[0];
- var min_ = minTime[1];
-
- while( hour_*100+min_ < maxTime[0]*100+maxTime[1] ){
-
- var $o = $('');
- var is_past_time = hour_ < todayDate.getHours() || (hour_ == todayDate.getHours() && min_ < todayDate.getMinutes());
- var is_past = isCurrentDay && is_past_time;
-
- $o.addClass('timelist_item');
- var oText = "";
- if($picker.data("amPmInTimeList")){
- oText = /*zpadding*/(hour_ > 12? hour_ - 12 : (hour_ < 1? 12 : hour_));
- oText += ":" + zpadding(min_);
- oText += (hour_ >= 12? "PM" : "AM");
- } else {
- oText = zpadding(hour_) + ":" + zpadding(min_);
- }
- $o.text(oText);
- $o.data("hour", hour_);
- $o.data("min", min_);
-
- $timelist.append($o);
-
- realDayObj.setHours(hour_);
- realDayObj.setMinutes(min_);
-
- if (
- ((minDate != null) && (minDate > realDayObj.getTime())) || ((maxDate != null) && (maxDate < realDayObj.getTime()))
- ) { // Out of range cell
- $o.addClass('out_of_range');
- } else if (isFutureOnly && is_past) { // Past cell
- $o.addClass('time_in_past');
- } else { // Normal cell
- /* Set event handler to time cell */
- $o.click(function() {
- if ($(this).hasClass('hover')) {
- $(this).removeClass('hover');
- }
- $(this).addClass('active');
-
- var $picker = getParentPickerObject($(this));
- var date = getPickedDate($picker);
- var hour = $(this).data("hour");
- var min = $(this).data("min");
- draw($picker, {
- "isAnim": false,
- "isOutputToInputObject": true
- }, date.getFullYear(), date.getMonth(), date.getDate(), hour, min);
-
- if ($picker.data("isInline") === false && $picker.data("closeOnSelected")){
- // Close a picker
- ActivePickerId = -1;
- $picker.hide();
- }
- });
-
- $o.hover(function() {
- if (! $(this).hasClass('active')) {
- $(this).addClass('hover');
- }
- }, function() {
- if ($(this).hasClass('hover')) {
- $(this).removeClass('hover');
- }
- });
- }
-
- if (hour_ == date.getHours() && min_ == date.getMinutes()) { /* selected time */
- $o.addClass('active');
- timelist_activeTimeCell_offsetTop = $o.offset().top;
- }
-
- min_ += minuteInterval;
- if (min_ >= 60){
- min_ = min_ - 60;
- hour_++;
- }
-
- }
-
- /* Scroll the timelist */
- if(isScroll === true){
- /* Scroll to new active time-cell position */
- $timelist.scrollTop(timelist_activeTimeCell_offsetTop - $timelist.offset().top);
- }else{
- /* Scroll to position that before redraw. */
- $timelist.scrollTop(drawBefore_timeList_scrollTop);
- }
- }
-
- /* Fade-in animation */
- if (isAnim === true) {
- if(changePoint == "calendar"){
- $calendar.fadeTo("fast", 1.0);
- }else if(changePoint == "timelist"){
- $timelist.fadeTo("fast", 1.0);
- }
- }
-
- /* Output to InputForm */
- if (isOutputToInputObject === true) {
- outputToInputObject($picker);
- }
- };
-
- /* Check for object type */
- var isObj = function(type, obj) {
- /* http://qiita.com/Layzie/items/465e715dae14e2f601de */
- var clas = Object.prototype.toString.call(obj).slice(8, -1);
- return obj !== undefined && obj !== null && clas === type;
- };
-
- var init = function($obj, opt) {
- /* Container */
- var $picker = $(' ');
-
- $picker.destroy = function() {
- window.alert('destroy!');
- };
-
- $picker.addClass('datepicker');
- $obj.append($picker);
-
- /* Set current date */
- if(!opt.current) {
- opt.current = new Date();
- } else {
- var format = getDateFormat(opt.dateFormat, opt.locale, opt.dateOnly);
- var date = parseDate(opt.current, format);
- if (date) {
- opt.current = date;
- } else {
- opt.current = new Date();
- }
- }
-
- /* Set options data to container object */
- if (opt.inputObjectId != null) {
- $picker.data("inputObjectId", opt.inputObjectId);
- }
- $picker.data("dateOnly", opt.dateOnly);
- $picker.data("pickerId", PickerObjects.length);
- $picker.data("dateFormat", opt.dateFormat);
- $picker.data("locale", opt.locale);
- $picker.data("firstDayOfWeek", opt.firstDayOfWeek);
- $picker.data("animation", opt.animation);
- $picker.data("closeOnSelected", opt.closeOnSelected);
- $picker.data("timelistScroll", opt.timelistScroll);
- $picker.data("calendarMouseScroll", opt.calendarMouseScroll);
- $picker.data("todayButton", opt.todayButton);
- $picker.data("closeButton", opt.closeButton);
- $picker.data('futureOnly', opt.futureOnly);
- $picker.data('onShow', opt.onShow);
- $picker.data('onHide', opt.onHide);
- $picker.data('onInit', opt.onInit);
- $picker.data('allowWdays', opt.allowWdays);
-
- if(opt.amPmInTimeList === true){
- $picker.data('amPmInTimeList', true);
- } else {
- $picker.data('amPmInTimeList', false);
- }
-
- var minDate = Date.parse(opt.minDate);
- if (isNaN(minDate)) { // invalid date?
- $picker.data('minDate', null); // set to null
- } else {
- $picker.data('minDate', minDate);
- }
-
- var maxDate = Date.parse(opt.maxDate);
- if (isNaN(maxDate)) { // invalid date?
- $picker.data('maxDate', null); // set to null
- } else {
- $picker.data('maxDate', maxDate);
- }
- $picker.data("state", 0);
-
- if( 5 <= opt.minuteInterval && opt.minuteInterval <= 30 ){
- $picker.data("minuteInterval", opt.minuteInterval);
- } else {
- $picker.data("minuteInterval", 30);
- }
- opt.minTime = opt.minTime.split(':');
- opt.maxTime = opt.maxTime.split(':');
-
- if(! ((opt.minTime[0] >= 0 ) && (opt.minTime[0] <24 ))){
- opt.minTime[0]="00";
- }
- if(! ((opt.maxTime[0] >= 0 ) && (opt.maxTime[0] <24 ))){
- opt.maxTime[0]="23";
- }
- if(! ((opt.minTime[1] >= 0 ) && (opt.minTime[1] <60 ))){
- opt.minTime[1]="00";
- }
- if(! ((opt.maxTime[1] >= 0 ) && (opt.maxTime[1] <24 ))){
- opt.maxTime[1]="59";
- }
- opt.minTime[0]=parseInt(opt.minTime[0]);
- opt.minTime[1]=parseInt(opt.minTime[1]);
- opt.maxTime[0]=parseInt(opt.maxTime[0]);
- opt.maxTime[1]=parseInt(opt.maxTime[1]);
- $picker.data('minTime', opt.minTime);
- $picker.data('maxTime', opt.maxTime);
-
- /* Header */
- var $header = $(' ');
- $header.addClass('datepicker_header');
- $picker.append($header);
- /* InnerContainer*/
- var $inner = $(' ');
- $inner.addClass('datepicker_inner_container');
- $picker.append($inner);
- /* Calendar */
- var $calendar = $(' ');
- $calendar.addClass('datepicker_calendar');
- var $table = $(' ');
- $table.addClass('datepicker_table');
- $calendar.append($table);
- $inner.append($calendar);
- /* Timelist */
- var $timelist = $('');
- $timelist.addClass('datepicker_timelist');
- $inner.append($timelist);
-
- /* Set event handler to picker */
- $picker.hover(
- function(){
- ActivePickerId = $(this).data("pickerId");
- },
- function(){
- ActivePickerId = -1;
- }
- );
-
- /* Set event-handler to calendar */
- if (opt.calendarMouseScroll) {
- if (window.sidebar) { // Mozilla Firefox
- $calendar.bind('DOMMouseScroll', function(e){ // Change a month with mouse wheel scroll for Fx
- var $picker = getParentPickerObject($(this));
-
- // up,left [delta < 0] down,right [delta > 0]
- var delta = e.originalEvent.detail;
- /*
- // this code need to be commented - it's seems to be unnecessary
- // normalization (/3) is not needed as we move one month back or forth
- if(e.originalEvent.axis !== undefined && e.originalEvent.axis == e.originalEvent.HORIZONTAL_AXIS){
- e.deltaX = delta;
- e.deltaY = 0;
- } else {
- e.deltaX = 0;
- e.deltaY = delta;
- }
- e.deltaX /= 3;
- e.deltaY /= 3;
- */
- if(delta > 0) {
- nextMonth($picker);
- } else {
- beforeMonth($picker);
- }
- return false;
- });
- } else { // Other browsers
- $calendar.bind('mousewheel', function(e){ // Change a month with mouse wheel scroll
- var $picker = getParentPickerObject($(this));
- // up [delta > 0] down [delta < 0]
- if(e.originalEvent.wheelDelta /120 > 0) {
- beforeMonth($picker);
- } else {
- nextMonth($picker);
- }
- return false;
- });
- }
- }
-
- PickerObjects.push($picker);
-
- draw_date($picker, {
- "isAnim": true,
- "isOutputToInputObject": opt.autodateOnStart
- }, opt.current);
- };
-
- var getDefaults = function() {
- return {
- "current": null,
- "dateFormat": "default",
- "locale": "en",
- "animation": true,
- "minuteInterval": 30,
- "firstDayOfWeek": 0,
- "closeOnSelected": false,
- "timelistScroll": true,
- "calendarMouseScroll": true,
- "todayButton": true,
- "closeButton": true,
- "dateOnly": false,
- "futureOnly": false,
- "minDate" : null,
- "maxDate" : null,
- "autodateOnStart": true,
- "minTime":"00:00",
- "maxTime":"23:59",
- "onShow": null,
- "onHide": null,
- "allowWdays": null,
- "amPmInTimeList": false
- };
- };
-
- /**
- * Initialize dtpicker
- */
- $.fn.dtpicker = function(config) {
- var date = new Date();
- var defaults = getDefaults();
-
- if(typeof config === "undefined" || config.closeButton !== true){
- defaults.closeButton = false;
- }
-
- defaults.inputObjectId = undefined;
- var options = $.extend(defaults, config);
-
- return this.each(function(i) {
- init($(this), options);
- });
- };
-
- /**
- * Initialize dtpicker, append to Text input field
- * */
- $.fn.appendDtpicker = function(config) {
- var date = new Date();
- var defaults = getDefaults();
-
- if(typeof config !== "undefined" && config.inline === true && config.closeButton !== true){
- defaults.closeButton = false;
- }
-
- defaults.inline = false;
- var options = $.extend(defaults, config);
-
- return this.each(function(i) {
- /* Checking exist a picker */
- var input = this;
- if(0 < $(PickerObjects[$(input).data('pickerId')]).length) {
- console.log("dtpicker - Already exist appended picker");
- return;
- }
-
- /* Add input-field with inputsObjects array */
- var inputObjectId = InputObjects.length;
- InputObjects.push(input);
-
- options.inputObjectId = inputObjectId;
-
- /* Current date */
- var date, strDate, strTime;
- if($(input).val() != null && $(input).val() !== ""){
- options.current = $(input).val();
- }
-
- /* Make parent-div for picker */
- var $d = $(' ');
- if(options.inline){ // Inline mode
- $d.insertAfter(input);
- } else { // Float mode
- $d.css("position","absolute");
- $('body').append($d);
- }
-
- /* Initialize picker */
-
- var pickerId = PickerObjects.length;
-
- var $picker_parent = $($d).dtpicker(options); // call dtpicker() method
-
- var $picker = $picker_parent.children('.datepicker');
-
- /* Link input-field with picker*/
- $(input).data('pickerId', pickerId);
-
- /* Set event handler to input-field */
-
- $(input).keyup(function() {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($input.val() != null && (
- $input.data('beforeVal') == null ||
- ( $input.data('beforeVal') != null && $input.data('beforeVal') != $input.val()) )
- ) { /* beforeValue == null || beforeValue != nowValue */
- var format = getDateFormat($picker.data('dateFormat'), $picker.data('locale'), $picker.data('dateOnly'));
- var date = parseDate($input.val(), format);
- //console.log("dtpicker - inputKeyup - format: " + format + ", date: " + $input.val() + " -> " + date);
- if (date) {
- draw_date($picker, {
- "isAnim":true,
- "isOutputToInputObject":false
- }, date);
- }
- }
- $input.data('beforeVal', $input.val());
- });
-
- $(input).change(function(){
- $(this).trigger('keyup');
- });
-
- var handler = new PickerHandler($picker, $(input));
-
- if(options.inline === true){
- /* inline mode */
- $picker.data('isInline',true);
- } else {
- /* float mode */
- $picker.data('isInline',false);
- $picker_parent.css({
- "zIndex": 100
- });
- $picker.css("width","auto");
-
- /* Hide this picker */
- $picker.hide();
-
- /* Set onClick event handler for input-field */
- $(input).on('click, focus',function(){
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
-
- // Generate the handler of a picker
- var handler = new PickerHandler($picker, $input);
- // Get the display state of a picker
- var is_showed = handler.isShow();
- if (!is_showed) {
- // Show a picker
- handler.show();
-
- // Call a event-hanlder
- var func = $picker.data('onShow');
- if (func != null) {
- console.log("dtpicker- Call the onShow handler");
- func(handler);
- }
- }
- });
-
- // Set an event handler for resizing of a window
- (function(handler){
- $(window).resize(function(){
- handler._relocate();
- });
- $(window).scroll(function(){
- handler._relocate();
- });
- })(handler);
- }
-
- // Set an event handler for removing of an input-field
- $(input).bind('destroyed', function() {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- // Generate the handler of a picker
- var handler = new PickerHandler($picker, $input);
- // Destroy a picker
- handler.destroy();
- });
-
- // Call a event-handler
- var func = $picker.data('onInit');
- if (func != null) {
- console.log("dtpicker- Call the onInit handler");
- func(handler);
- }
- });
- };
-
- /**
- * Handle a appended dtpicker
- * */
- var methods = {
- show : function( ) {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($picker != null) {
- var handler = new PickerHandler($picker, $input);
- // Show a picker
- handler.show();
- }
- },
- hide : function( ) {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($picker != null) {
- var handler = new PickerHandler($picker, $input);
- // Hide a picker
- handler.hide();
- }
- },
- setDate : function( date ) {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($picker != null) {
- var handler = new PickerHandler($picker, $input);
- // Set a date
- handler.setDate(date);
- }
- },
- getDate : function( ) {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($picker != null) {
- var handler = new PickerHandler($picker, $input);
- // Get a date
- return handler.getDate();
- }
- },
- destroy : function( ) {
- var $input = $(this);
- var $picker = $(PickerObjects[$input.data('pickerId')]);
- if ($picker != null) {
- var handler = new PickerHandler($picker, $input);
- // Destroy a picker
- handler.destroy();
- }
- }
- };
-
- $.fn.handleDtpicker = function( method ) {
- if ( methods[method] ) {
- return methods[ method ].apply( this, Array.prototype.slice.call( arguments, 1 ));
- } else if ( typeof method === 'object' || ! method ) {
- return methods.init.apply( this, arguments );
- } else {
- $.error( 'Method ' + method + ' does not exist on jQuery.handleDtpicker' );
- }
- };
-
- if (!window.console) { // Not available a console on this environment.
- window.console = {};
- window.console.log = function(){};
- }
-
- /* Define a special event for catch when destroy of an input-field. */
- $.event.special.destroyed = {
- remove: function(o) {
- if (o.handler) {
- o.handler.apply(this, arguments);
- }
- }
- };
-
- /* Set event handler to Body element, for hide a floated-picker */
- $(function(){
- $('body').click(function(){
- for(var i=0;i = minlength
- }
- }
-
- Validator.prototype.validateInput = function (e) {
- var $el = $(e.target)
- var prevErrors = $el.data('bs.validator.errors')
- var errors
-
- if ($el.is('[type="radio"]')) $el = this.$element.find('input[name="' + $el.attr('name') + '"]')
-
- this.$element.trigger(e = $.Event('validate.bs.validator', {relatedTarget: $el[0]}))
-
- if (e.isDefaultPrevented()) return
-
- var self = this
-
- this.runValidators($el).done(function (errors) {
- $el.data('bs.validator.errors', errors)
-
- errors.length ? self.showErrors($el) : self.clearErrors($el)
-
- if (!prevErrors || errors.toString() !== prevErrors.toString()) {
- e = errors.length
- ? $.Event('invalid.bs.validator', {relatedTarget: $el[0], detail: errors})
- : $.Event('valid.bs.validator', {relatedTarget: $el[0], detail: prevErrors})
-
- self.$element.trigger(e)
- }
-
- self.toggleSubmit()
-
- self.$element.trigger($.Event('validated.bs.validator', {relatedTarget: $el[0]}))
- })
- }
-
-
- Validator.prototype.runValidators = function ($el) {
- var errors = []
- var validators = [Validator.VALIDATORS.native]
- var deferred = $.Deferred()
- var options = this.options
-
- $el.data('bs.validator.deferred') && $el.data('bs.validator.deferred').reject()
- $el.data('bs.validator.deferred', deferred)
-
- function getErrorMessage(key) {
- return $el.data(key + '-error')
- || $el.data('error')
- || key == 'native' && $el[0].validationMessage
- || options.errors[key]
- }
-
- $.each(Validator.VALIDATORS, $.proxy(function (key, validator) {
- if (($el.data(key) || key == 'native') && !validator.call(this, $el)) {
- var error = getErrorMessage(key)
- !~errors.indexOf(error) && errors.push(error)
- }
- }, this))
-
- if (!errors.length && $el.val() && $el.data('remote')) {
- this.defer($el, function () {
- var data = {}
- data[$el.attr('name')] = $el.val()
- $.get($el.data('remote'), data)
- .fail(function (jqXHR, textStatus, error) { errors.push(getErrorMessage('remote') || error) })
- .always(function () { deferred.resolve(errors)})
- })
- } else deferred.resolve(errors)
-
- return deferred.promise()
- }
-
- Validator.prototype.validate = function () {
- var delay = this.options.delay
-
- this.options.delay = 0
- this.$element.find(':input').trigger('input.bs.validator')
- this.options.delay = delay
-
- return this
- }
-
- Validator.prototype.showErrors = function ($el) {
- var method = this.options.html ? 'html' : 'text'
-
- this.defer($el, function () {
- var $group = $el.closest('.form-group')
- var $block = $group.find('.help-block.with-errors')
- var $feedback = $group.find('.form-control-feedback')
- var errors = $el.data('bs.validator.errors')
-
- if (!errors.length) return
-
- errors = $('')
- .addClass('list-unstyled')
- .append($.map(errors, function (error) { return $('')[method](error) }))
-
- $block.data('bs.validator.originalContent') === undefined && $block.data('bs.validator.originalContent', $block.html())
- $block.empty().append(errors)
- $group.removeClass('has-success')
- $group.addClass('has-error')
-
- $feedback.removeClass('glyphicon-ok')
- $feedback.addClass('glyphicon-warning-sign')
- })
- }
-
- Validator.prototype.clearErrors = function ($el) {
- var $group = $el.closest('.form-group')
- var $block = $group.find('.help-block.with-errors')
- var $feedback = $group.find('.form-control-feedback')
-
- $block.html($block.data('bs.validator.originalContent'))
- $group.removeClass('has-error')
- $group.addClass('has-success')
- $feedback.removeClass('glyphicon-warning-sign')
- $feedback.addClass('glyphicon-ok')
- }
-
- Validator.prototype.hasErrors = function () {
- function fieldErrors() {
- return !!($(this).data('bs.validator.errors') || []).length
- }
-
- return !!this.$element.find(':input:enabled').filter(fieldErrors).length
- }
-
- Validator.prototype.isIncomplete = function () {
- function fieldIncomplete() {
- return this.type === 'checkbox' ? !this.checked :
- this.type === 'radio' ? !$('[name="' + this.name + '"]:checked').length :
- $.trim(this.value) === ''
- }
-
- return !!this.$element.find(':input[required]:enabled').filter(fieldIncomplete).length
- }
-
- Validator.prototype.onSubmit = function (e) {
- this.validate()
- if (this.isIncomplete() || this.hasErrors()) e.preventDefault()
- }
-
- Validator.prototype.toggleSubmit = function () {
- if(!this.options.disable) return
- var $btn = this.$element.find('input[type="submit"], button[type="submit"]')
- $btn.toggleClass('disabled', this.isIncomplete() || this.hasErrors())
- .css({'pointer-events': 'all', 'cursor': 'pointer'})
- }
-
- Validator.prototype.defer = function ($el, callback) {
- if (!this.options.delay) return callback()
- window.clearTimeout($el.data('bs.validator.timeout'))
- $el.data('bs.validator.timeout', window.setTimeout(callback, this.options.delay))
- }
-
- Validator.prototype.destroy = function () {
- this.$element
- .removeAttr('novalidate')
- .removeData('bs.validator')
- .off('.bs.validator')
-
- this.$element.find(':input')
- .off('.bs.validator')
- .removeData(['bs.validator.errors', 'bs.validator.deferred'])
- .each(function () {
- var $this = $(this)
- var timeout = $this.data('bs.validator.timeout')
- window.clearTimeout(timeout) && $this.removeData('bs.validator.timeout')
- })
-
- this.$element.find('.help-block.with-errors').each(function () {
- var $this = $(this)
- var originalContent = $this.data('bs.validator.originalContent')
-
- $this
- .removeData('bs.validator.originalContent')
- .html(originalContent)
- })
-
- this.$element.find('input[type="submit"], button[type="submit"]').removeClass('disabled')
-
- this.$element.find('.has-error').removeClass('has-error')
-
- return this
- }
-
- // VALIDATOR PLUGIN DEFINITION
- // ===========================
-
-
- function Plugin(option) {
- return this.each(function () {
- var $this = $(this)
- var options = $.extend({}, Validator.DEFAULTS, $this.data(), typeof option == 'object' && option)
- var data = $this.data('bs.validator')
-
- if (!data && option == 'destroy') return
- if (!data) $this.data('bs.validator', (data = new Validator(this, options)))
- if (typeof option == 'string') data[option]()
- })
- }
-
- var old = $.fn.validator
-
- $.fn.validator = Plugin
- $.fn.validator.Constructor = Validator
-
-
- // VALIDATOR NO CONFLICT
- // =====================
-
- $.fn.validator.noConflict = function () {
- $.fn.validator = old
- return this
- }
-
-
- // VALIDATOR DATA-API
- // ==================
-
- $(window).on('load', function () {
- $('form[data-toggle="validator"]').each(function () {
- var $form = $(this)
- Plugin.call($form, $form.data())
- })
- })
-
-}(jQuery);
diff --git a/spring-security-oauth/src/test/java/org/baeldung/classifier/RedditClassifierTest.java b/spring-security-oauth/src/test/java/org/baeldung/classifier/RedditClassifierTest.java
deleted file mode 100644
index 6b51c852c7..0000000000
--- a/spring-security-oauth/src/test/java/org/baeldung/classifier/RedditClassifierTest.java
+++ /dev/null
@@ -1,44 +0,0 @@
-package org.baeldung.classifier;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-
-import org.baeldung.reddit.classifier.RedditClassifier;
-import org.baeldung.reddit.classifier.RedditDataCollector;
-import org.junit.Ignore;
-import org.junit.Test;
-
-@Ignore
-public class RedditClassifierTest {
-
- @Test
- public void whenUsingDefaultClassifier_thenAccurate() throws IOException {
- final RedditClassifier classifier = new RedditClassifier();
- classifier.trainClassifier(RedditDataCollector.DATA_FILE);
- final double result = classifier.getAccuracy();
- System.out.println("==== Default Classifier Accuracy = " + result);
- System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
- assertTrue(result > 0.7);
- }
-
- @Test
- public void givenSmallerPoolSizeAndFeatures_whenUsingCustomClassifier_thenAccurate() throws IOException {
- final RedditClassifier classifier = new RedditClassifier(100, 500, 7);
- classifier.trainClassifier(RedditDataCollector.DATA_FILE);
- final double result = classifier.getAccuracy();
- System.out.println("==== Custom Classifier (small) Accuracy = " + result);
- System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
- assertTrue(result < 0.7);
- }
-
- @Test
- public void givenLargerPoolSizeAndFeatures_whenUsingCustomClassifier_thenAccurate() throws IOException {
- final RedditClassifier classifier = new RedditClassifier(250, 2500, 7);
- classifier.trainClassifier(RedditDataCollector.DATA_FILE);
- final double result = classifier.getAccuracy();
- System.out.println("==== Custom Classifier (large) Accuracy = " + result);
- System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++\n\n\n");
- assertTrue(result > 0.7);
- }
-}
diff --git a/spring-security-oauth/src/test/java/org/baeldung/persistence/PersistenceJPATest.java b/spring-security-oauth/src/test/java/org/baeldung/persistence/PersistenceJPATest.java
deleted file mode 100644
index 9b6591497c..0000000000
--- a/spring-security-oauth/src/test/java/org/baeldung/persistence/PersistenceJPATest.java
+++ /dev/null
@@ -1,106 +0,0 @@
-package org.baeldung.persistence;
-
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.hamcrest.collection.IsIn.isIn;
-import static org.hamcrest.core.IsNot.not;
-
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.List;
-
-import org.baeldung.persistence.dao.PostRepository;
-import org.baeldung.persistence.dao.UserRepository;
-import org.baeldung.persistence.model.Post;
-import org.baeldung.persistence.model.User;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.test.context.ContextConfiguration;
-import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import org.springframework.test.context.transaction.TransactionConfiguration;
-import org.springframework.transaction.annotation.Transactional;
-
-@RunWith(SpringJUnit4ClassRunner.class)
-@ContextConfiguration(classes = { TestJPAConfig.class })
-@Transactional
-@TransactionConfiguration
-// @Ignore
-public class PersistenceJPATest {
- @Autowired
- private PostRepository postRepository;
-
- @Autowired
- private UserRepository userRepository;
-
- private Post alreadySentPost, notSentYetOld, notSentYet;
-
- private User userJohn, userTom;
-
- private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
-
- @Before
- public void init() throws ParseException {
- userJohn = new User();
- userJohn.setUsername("John");
- userRepository.save(userJohn);
-
- userTom = new User();
- userTom.setUsername("Tom");
- userRepository.save(userTom);
-
- alreadySentPost = new Post();
- alreadySentPost.setTitle("First post title");
- alreadySentPost.setSent(true);
- alreadySentPost.setSubmissionDate(dateFormat.parse("2015-03-03 10:30"));
- alreadySentPost.setUser(userJohn);
- alreadySentPost.setSubreddit("funny");
- alreadySentPost.setUrl("www.example.com");
- postRepository.save(alreadySentPost);
-
- notSentYetOld = new Post();
- notSentYetOld.setTitle("Second post title");
- notSentYetOld.setSent(false);
- notSentYetOld.setSubmissionDate(dateFormat.parse("2015-03-03 11:00"));
- notSentYetOld.setUser(userTom);
- notSentYetOld.setSubreddit("funny");
- notSentYetOld.setUrl("www.example.com");
- postRepository.save(notSentYetOld);
-
- notSentYet = new Post();
- notSentYet.setTitle("Second post title");
- notSentYet.setSent(false);
- notSentYet.setSubmissionDate(dateFormat.parse("2015-03-03 11:30"));
- notSentYet.setUser(userJohn);
- notSentYet.setSubreddit("funny");
- notSentYet.setUrl("www.example.com");
- postRepository.save(notSentYet);
- }
-
- @Test
- public void whenGettingListOfSentPosts_thenCorrect() throws ParseException {
- final List results = postRepository.findBySubmissionDateBeforeAndIsSent(dateFormat.parse("2015-03-03 11:50"), true);
-
- assertThat(alreadySentPost, isIn(results));
- assertThat(notSentYet, not(isIn(results)));
- assertThat(notSentYetOld, not(isIn(results)));
- }
-
- @Test
- public void whenGettingListOfOldPosts_thenCorrect() throws ParseException {
- final List results = postRepository.findBySubmissionDateBeforeAndIsSent(dateFormat.parse("2015-03-03 11:01"), false);
-
- assertThat(notSentYetOld, isIn(results));
- assertThat(notSentYet, not(isIn(results)));
- assertThat(alreadySentPost, not(isIn(results)));
- }
-
- @Test
- public void whenGettingListOfSpecificuser_thenCorrect() throws ParseException {
- final List results = postRepository.findByUser(userTom);
- assertThat(notSentYetOld, isIn(results));
- assertThat(notSentYet, not(isIn(results)));
- assertThat(alreadySentPost, not(isIn(results)));
- }
-
-}
diff --git a/spring-security-oauth/src/test/java/org/baeldung/persistence/TestJPAConfig.java b/spring-security-oauth/src/test/java/org/baeldung/persistence/TestJPAConfig.java
deleted file mode 100644
index a3d29d7424..0000000000
--- a/spring-security-oauth/src/test/java/org/baeldung/persistence/TestJPAConfig.java
+++ /dev/null
@@ -1,73 +0,0 @@
-package org.baeldung.persistence;
-
-import java.util.Properties;
-
-import javax.sql.DataSource;
-
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Bean;
-import org.springframework.context.annotation.ComponentScan;
-import org.springframework.context.annotation.Configuration;
-import org.springframework.context.annotation.PropertySource;
-import org.springframework.core.env.Environment;
-import org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor;
-import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
-import org.springframework.jdbc.datasource.DriverManagerDataSource;
-import org.springframework.orm.jpa.JpaTransactionManager;
-import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
-import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
-import org.springframework.transaction.annotation.EnableTransactionManagement;
-
-@Configuration
-@EnableTransactionManagement
-@PropertySource({ "classpath:persistence-test.properties" })
-@ComponentScan({ "org.baeldung.persistence.model", "org.baeldung.persistence.dao" })
-@EnableJpaRepositories(basePackages = "org.baeldung.persistence.dao")
-public class TestJPAConfig {
- @Autowired
- private Environment env;
-
- public TestJPAConfig() {
- super();
- }
-
- @Bean
- public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
- final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
- em.setDataSource(dataSource());
- em.setPackagesToScan(new String[] { "org.baeldung.persistence.model" });
- final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
- em.setJpaVendorAdapter(vendorAdapter);
- em.setJpaProperties(additionalProperties());
- return em;
- }
-
- @Bean
- public DataSource dataSource() {
- final DriverManagerDataSource dataSource = new DriverManagerDataSource();
- dataSource.setDriverClassName(env.getProperty("jdbc.driverClassName"));
- dataSource.setUrl(env.getProperty("jdbc.url"));
- dataSource.setUsername(env.getProperty("jdbc.user"));
- dataSource.setPassword(env.getProperty("jdbc.pass"));
- return dataSource;
- }
-
- @Bean
- public JpaTransactionManager transactionManager() {
- final JpaTransactionManager transactionManager = new JpaTransactionManager();
- transactionManager.setEntityManagerFactory(entityManagerFactory().getObject());
- return transactionManager;
- }
-
- @Bean
- public PersistenceExceptionTranslationPostProcessor exceptionTranslation() {
- return new PersistenceExceptionTranslationPostProcessor();
- }
-
- final Properties additionalProperties() {
- final Properties hibernateProperties = new Properties();
- hibernateProperties.setProperty("hibernate.hbm2ddl.auto", env.getProperty("hibernate.hbm2ddl.auto", "create-drop"));
- hibernateProperties.setProperty("hibernate.dialect", env.getProperty("hibernate.dialect"));
- return hibernateProperties;
- }
-}
diff --git a/spring-security-oauth/src/test/resources/.gitignore b/spring-security-oauth/src/test/resources/.gitignore
deleted file mode 100644
index 86d0cb2726..0000000000
--- a/spring-security-oauth/src/test/resources/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-# Ignore everything in this directory
-*
-# Except this file
-!.gitignore
\ No newline at end of file
|