yavsc/web/Scripts/yavsc.js
Paul Schneider b8446c2d3e Improves notification system
* ICalendarManager.cs: WIP booking TODO a calendar provider

* NpgsqlProfileProvider.cs: Fixes the defaultValue specification from
  config file

* BlogsController.cs:
* AccountController.cs:
* CalendarController.cs: refactoring : the Yavsc controller name

* instdbws.sql: a new profile value : a boolean, `AllowCookies` :'{

* style.css: a class to display notification

* HomeController.cs: Notifies users this site uses cookies (what for
  an information!)
If authenticated, at dimissing this notification, the user's profile
  is updated,
and he'll not mess up anymore with the info.

* App.master:
* YavscHelpers.cs: adds usage of click_action value at
displaying a notification.

* yavsc.js: Implements the notification `click_action`

* Web.config: * enables anonymous profiles
* adds a new `allowcookies` profile property

* Web.csproj: Yavsc controller refactoring

* YaEvent.cs:
* IFreeDateSet.cs: WIP booking

* LocalizedText.resx:
* LocalizedText.fr.resx:
* LocalizedText.Designer.cs:
* LocalizedText.fr.Designer.cs: implements the message "uses cookies"

* YavscModel.csproj: refactoring

* Notification.cs: The Yavsc otification will start as a Google one
  ...
many properties are not yet used, but all seems usefull.

* Web.config: code prettying

* YavscController.cs: Gives Yavsc a concrete base controller
2015-10-28 21:02:03 +01:00

119 lines
3.1 KiB
JavaScript

var Yavsc = (function(apiBaseUrl){
var self = {};
self.dumpprops = function (obj) {
var str = "";
for(var k in obj)
if (obj.hasOwnProperty(k))
str += k + " = " + obj[k] + "\n";
return (str); }
self.apiBaseUrl = (apiBaseUrl || '/api');
self.showHide = function () {
var id = $(this).attr('did');
var target = $('#'+id);
if (target.hasClass('hidden')) {
target.removeClass('hidden');
if (typeof this.oldhtml == "undefined")
this.oldhtml = $(this).html();
$(this).html('['+this.oldhtml+']');
}
else {
target.addClass('hidden');
$(this).html(this.oldhtml);
}
};
self.dimiss = function () {
$(this).parent().remove();
};
self.ajax = function (method,data,callback) {
$.ajax({
url: self.apiBaseUrl+method,
type: "POST",
data: data,
success: function (response) {
if (callback) callback(response);
},
statusCode: {
400: Yavsc.onAjaxBadInput
},
error: Yavsc.onAjaxError});
};
self.onScroll = function() {
var $notifications = $('#notifications');
if ($notifications.has('*').length>0) {
if ($(window).scrollTop()>100) {
$notifications.addClass("dispmodal");
}
else {
$notifications.removeClass("dispmodal");
}}
};
self.notice = function (msg, callback, msgok) {
if (!msgok) msgok='Ok';
var note = $('<div class="notification">'+msg+'<br></div>');
var btn = $('<a class="actionlink"><i class="fa fa-check">'+msgok+'</i></a>');
if (callback) btn.click(callback);
btn.click(self.dimiss).appendTo(note);
note.appendTo("#notifications");
self.onScroll();
};
self.onAjaxBadInput = function (data)
{
if (!data) { Yavsc.notice('no data'); return; }
if (!data.responseJSON) { Yavsc.notice('no json data:'+data); return; }
if (!Array.isArray(data.responseJSON)) { Yavsc.notice('Bad Input: '+data.responseJSON); return; }
$.each(data.responseJSON, function (key, value) {
var errspanid = "Err_" + value.key;
var errspan = document.getElementById(errspanid);
if (errspan==null)
alert('enoent '+errspanid);
else
errspan.innerHTML=value.errors.join("<br/>");
});
};
self.onAjaxError = function (xhr, ajaxOptions, thrownError) {
if (xhr.status!=400)
Yavsc.notice(xhr.status+" : "+xhr.responseText);
};
$(document).ready(function(){
$('.maskable').each( function() {
var $mobj = $(this);
var $btnshow = $('#'+$mobj.data('btn-show'));
var $btnhide = $('#'+$mobj.data('btn-hide'));
var onClickHide = function(){
$mobj.addClass('hidden');
$btnshow.removeClass('hidden');
$btnhide.addClass('hidden');
};
$btnhide.click(onClickHide);
onClickHide();
$btnshow.click(function(){
$mobj.removeClass('hidden');
$btnshow.addClass('hidden');
$btnhide.removeClass('hidden');
});
});
});
$(document).ready(function(){
$body = $("body");
$(document).on({
ajaxStart: function() { $body.addClass("loading"); },
ajaxStop: function() { $body.removeClass("loading"); }
});
$(window).scroll(self.onScroll);
});
return self;
})();