fices the UI

This commit is contained in:
Paul Schneider 2026-06-15 02:55:22 +01:00
commit c1f4d19975
1213 changed files with 375635 additions and 19738 deletions

View file

@ -1,14 +0,0 @@
//@ts.check
var constraints = { audio: true, video: false }
navigator.mediaDevices.getUserMedia(constraints)
.then(function(stream) {
/* use the stream */
console.log("got stream!");
console.log(stream)
})
.catch(function(err) {
/* handle the error */
console.log(err)
});

View file

@ -1,315 +0,0 @@
window.ChatHubHandler = (function ($) {
/*
# chat control ids
## inputs
* msg_<rname> : input providing a room message
* pv_<uname> : input providing a private message
* command : input providing server command
* roomname : input (hidden or not) providing a room name
## persistent containers
* chatview : the global container
* rooms : container from room displays
* pvs : container from pv displays
* server : container for server messages
## temporary containers
* room_<rname> : room message list
* pv_<uname> : private discussion display
## css classes
* form-control
* btn btn-default
*/
$.fn.filterByData = function (prop, val) {
return this.filter(function () { return $(this).data(prop) == val; });
};
var ChatView = function ($view, full) {
if (!full) throw new Error('not implemented');
// the channel list
var chans = [];
// private chat list
var userlist = [];
var frontChanId;
var ulist = $('<ul></ul>').addClass('userlist');
var notifications = $('<ul></ul>').addClass('notifs');
ulist.appendTo($view);
notifications.appendTo($view);
var onUserDisconnected = function (uname) {
$('#u' + uname).remove();
};
var onUserConnected = function (username) {
addChatUser(username);
};
var connection = new signalR.HubConnectionBuilder().withUrl("/chatHub")
.configureLogging(signalR.LogLevel.Debug).build();
connection.on('ReceiveMessage', (m) => {
var $userTag = $('<a>' + htmlEncode(m.name) + '</a>').click(function () {
buildPv(m.name);
});
var $li = $('<li class="discussion"></li>');
$userTag.appendTo($li);
$li.append(' ' + htmlEncode(m.message));
$li.appendTo($('#r' + m.room));
});
connection.on("addPV", (name, message) => {
if (!$('#mute').prop('checked')) {
audio.play();
}
buildPv(name);
// Add the pv to the page.
$('#u' + name).append('<li class="pv"><strong>' + htmlEncode(name) + '</strong>: ' + htmlEncode(message) + '</li>');
});
connection.on("notifyRoom", (tag, targetid, message) => {
// Add the notification to the page.
if (tag === 'connected' || tag === 'reconnected') {
onUserConnected(targetid, message);
return;
} else if (tag === 'disconnected') {
onUserDisconnected(targetid, message);
return;
}
// eslint-disable-next-line no-warning-comments
// TODO reconnected userpart userjoin deniedpv
$('<li></li>').addClass(tag).append(tag + ': ').append(message).addClass(tag).appendTo($('#room_' + targetid));
});
connection.on("notifyUser", (tag, targetid, message) => {
// Add the notification to the page.
if (tag === 'connected' || tag === 'reconnected') {
onUserConnected(targetid, message);
return;
} else if (tag === 'disconnected') {
onUserDisconnected(targetid, message);
return;
}
$('<li></li>').append(tag + ': ' + targetid + ': ').append(message).addClass(tag).appendTo(notifications);
});
connection.on("notifyUserInRoom", (tag, room, message) => {
$('<li></li>').append(tag + ': ').append(message).addClass(tag).appendTo($('#room_' + room));
});
connection.on("addPublicStream", (pubStrInfo) => {
$('<li></li>').append(pubStrInfo.sender + ': ')
.append('<a href="' + pubStrInfo.url + '">' + pubStrInfo.title + '</a>').append('[' + pubStrInfo.mediaType + ']').addClass('streaminfo').appendTo(notifications);
});
connection.on("push", (what, data) => {
$('<li></li>').append(what + ': ')
.append(data).addClass('event').appendTo(notifications);
});
var setChanInfo = function (chanInfo) {
if (chanInfo) {
var chanId = 'r' + chanInfo.Name;
$('#tv_' + chanId).replaceWith(chanInfo.Topic);
}
};
var setActiveChan = function (chanId) {
if (frontChanId != chanId) {
if (frontChanId) {
$('#sel_' + frontChanId).addClass('btn-primary');
$('#v' + frontChanId).addClass('hidden');
}
frontChanId = chanId;
$('#sel_' + chanId).removeClass('btn-primary');
$('#v' + chanId).removeClass('hidden');
$('#inp_' + chanId).focus();
}
};
connection.on("joint", (chatInfo) => {
setChanInfo(chatInfo);
setActiveChan('r' + chatInfo.Name);
});
var join = function (roomName) {
connection.invoke("join", roomName)
.catch(function (err) {
return console.error(err.toString());
});
};
var chatbar = $('<div class="chatbar form-group"></div>');
var roomjoin = $('<div class="chatctl" ></div>');
var roomlist = $('<div class="roomlist"></div>');
roomlist.appendTo(chatbar);
var ptc = $('<img src="/images/ptcroix.png" >').addClass('ptcroix');
$('<label for="channame">Join&nbsp;:</label>')
.appendTo(roomjoin);
var chanName = $('<input id="channame" title="channel name" hint="yavsc" >');
chanName.appendTo(roomjoin);
ptc.appendTo(roomjoin);
roomjoin.appendTo(chatbar);
chatbar.appendTo($view);
var chatlist = $('<div class="chatlist" ></div>');
chatlist.appendTo($view);
var buildChan = function (chdp, chanType, chanName, sendCmd) {
var chanId = chanType + chanName;
var roomTag = $('<a>' + chdp + chanName + '</a>').addClass('btn');
roomTag.prop('id', 'sel_' + chanId).click(function () {
setActiveChan(chanId);
$(this).removeClass('btn-primary');
});
roomTag.appendTo(roomlist);
var roomview = $('<div></div>').addClass('container');
roomview.appendTo(chatlist);
roomview.prop('id', 'v' + chanId);
$('<div></div>').prop('id', 'tv_' + chanId).appendTo(roomview);
var msglist = $('<ul></ul>').addClass('mesglist');
msglist.prop('id', chanId);
msglist.appendTo(roomview);
$('<input type="text">')
.prop('id', 'inp_' + chanId)
.prop('enable', false)
.prop('hint', 'hello')
.prop('title', 'send to ' + chanName)
.addClass('form-control')
.keydown(function (ev) {
if (ev.which == 13) {
if (this.value.length == 0) return;
connection.invoke(sendCmd, chanName, this.value);
this.value = '';
}
}).appendTo(roomview);
if (chanType == 'r') chans.push(chanName);
else if (chanType == 'u' || chanType == 'a') userlist.push(chanName);
setActiveChan(chanId);
};
var buildRoom = function (roomName) {
if (!chans.some(function (cname) { return cname == roomName; })) {
buildChan('#', 'r', roomName, "send");
}
};
var DestroyRoom = function () {
if (frontChanId) {
$('#v' + frontChanId).remove();
$('#sel_' + frontChanId).remove();
frontChanId = null;
}
}
var buildPv = function (userName) {
if (!userlist.some(function (uname) { return uname == userName; })) {
if (userName[0] == '?') buildChan('@?', 'a', userName.slice(1), "sendPV");
else buildChan('@', 'u', userName, "sendPV");
}
};
/*var getUsers = function () {
$.get('/api/chat/users').done(function (users) {
$.each(users, function () {
var user = this;
addChatUser(user.UserName);
});
});
};*/
$view.data('chans').split(',').forEach(function (chan) {
buildRoom(chan);
});
function onCx() {
$view.removeClass('disabled');
setTimeout(function () {
chans.forEach(function (chan) {
join(chan);
});
}, 120);
}
function onDisCx() {
$view.addClass('disabled');
}
connection.onclose(function () {
onDisCx();
setTimeout(startCx, 30000); // Re-start connection after 30 seconds
});
var startCx = function(){connection.start().then(onCx)};
startCx();
chanName.keydown(function (event) {
if (event.which == 13) {
if (this.value.length == 0) return;
buildRoom(this.value);
join(this.value);
this.value = '';
}
// else TODO showRoomInfo(this.value);
});
ptc.click(function () {
DestroyRoom();
});
// eslint-disable-next-line no-warning-comments
// TODO get this data from the chatview element
var audio = new Audio('/sounds/bell.mp3');
$('#command').keydown(function (event) {
if (event.which == 13) {
// eslint-disable-next-line no-warning-comments
// TODO server command: sendCommand()
}
});
var addChatUser = function (uname) {
ulist.children('li').filter(function () {
return $(this).data('uname') == uname;
}).remove();
$('<li class="user"><img src="/Avatars/' + uname + '.xs.png"> ' + uname + '</li>')
.data('uname', uname)
.css('cursor', 'pointer')
.click(function () {
buildPv(uname);
})
.appendTo(ulist);
};
// This optional function html-encodes messages for display in the page.
function htmlEncode(value) {
var encodedValue = $('<div />').text(value).html();
return encodedValue;
}
$(window).on("unload", function () { connection.stop() });
};
$(document).ready(function ($) {
ChatView($('#chatview'), true);
});
})(window.jQuery);

View file

@ -1,153 +0,0 @@
$.widget("psc.blogcomment", {
options: {
apictrlr: null,
authorId: null,
authorName: null,
omob: '#ffe08030',
omof: '#501208',
bgc: '#fff',
fgc: '#000',
lang: 'fr-FR',
allowCoc: true
},
editable: false,
editting: false,
hideBtn: null,
delBtn: null,
cmtInput: null,
cmtBtn: null,
ctlBtn: null,
collapsed: false,
subCmts: null,
_create: function() {
var _this = this;
this.element.addClass("blogcomment");
var date = new Date(this.element.data("date"));
var username = this.element.data("username");
this.editable = this.element.data("allow-edit");
this.element.prepend('<div class="commentmeta"><img class="avatar" src="/Avatars/' + username + '.xs.png" class="smalltofhol" title="' + username + '" /><div class="cmtdatetime">' +
date.toLocaleDateString(this.options.lang) + ' ' + date.toLocaleTimeString(this.options.lang) + '</div></div>')
this.element.on("mouseenter", this.onMouseEnter);
this.element.on("mouseleave", this.onMouseLeave);
this.ctlBtn = $('<button class="btn"><span class="ui-icon ui-icon-plus"></span></button>').on("click", function(ev) { _this.toggleCollapse(_this, ev) }).appendTo(_this.element);
},
toggleCollapse: function(_this, ev) {
_this.collapsed = !_this.collapsed;
var icon = $(_this.ctlBtn).children().first();
if (_this.collapsed) {
icon.removeClass('ui-icon-plus');
icon.addClass('ui-icon-minus');
} else {
icon.removeClass('ui-icon-minus');
icon.addClass('ui-icon-plus');
}
if (_this.editable) {
_this.toggleEdit(_this, ev)
}
if (_this.options.allowCoc) {
_this.toggleComment(_this, ev)
}
},
toggleEdit: function(_this, ev) {
if (!_this.delBtn) {
_this.delBtn = $("<button class=\"btn btn-warning\">Supprimer</button>");
_this.delBtn.on("click", function(ev) { _this.doDeleteComment(_this, ev) }).appendTo(_this.element);
} else {
_this.delBtn.remove();
_this.delBtn = null;
}
},
toggleComment: function(_this, ev) {
if (!_this.cmtBtn) {
if (!_this.subCmts) {
_this.subCmts = $(_this.element).children('div.subcomments');
if (_this.subCmts.length == 0) {
_this.subCmts = $('<div></div>').addClass('subcomments');
_this.subCmts.appendTo(_this.element);
}
}
_this.cmtInput = $('<input type="text" placeholder="Votre réponse"/>');
_this.cmtInput.appendTo(_this.element);
_this.cmtBtn = $("<button class=\"btn btn-default\">Répondre</button>");
_this.cmtBtn.on("click", function(ev) { _this.doCoC(_this, ev) }).appendTo(_this.element);
} else {
_this.cmtInput.remove();
_this.cmtBtn.remove();
_this.cmtBtn = null;
}
},
onMouseEnter: function() {
$(this).animate({
backgroundColor: $.psc.blogcomment.prototype.options.omob,
color: $.psc.blogcomment.prototype.options.omof
}, 400);
},
onMouseLeave: function() {
$(this).animate({
backgroundColor: $.psc.blogcomment.prototype.options.bgc,
color: $.psc.blogcomment.prototype.options.fgc
}, 400);
},
doDeleteComment: function(_this, ev) {
$.ajax({
async: true,
cache: false,
type: 'POST',
method: 'DELETE',
error: function(xhr, data) {
$('span.field-validation-valid[data-valmsg-for="Content"]').html(
"Une erreur est survenue : " + xhr.status + "<br/>"
).focus()
},
success: function(data) {
_this.element.remove()
},
url: _this.options.apictrlr + '/' + $(_this.element).data("id")
});
},
doCoC: function(_this, ev) {
var postId = this.element.data('receiver-id');
var comment = _this.cmtInput.val();
var cmtId = $(_this.element).data("id");
var data = {
Content: comment,
ReceiverId: postId,
ParentId: cmtId,
AuthorId: _this.options.authorId
};
$.ajax({
async: true,
cache: false,
type: 'POST',
method: 'POST',
contentType: "application/json",
data: JSON.stringify(data),
error: function(xhr, erd) {
console.log('err');
console.log(xhr);
console.log(erd);
$('span.field-validation-valid[data-valmsg-for="Content"]').html(
"Une erreur est survenue : " + xhr.status + "<br/>" +
"<code><pre>" + xhr.responseText + "</pre></code>"
)
},
success: function(data) {
_this.cmtInput.val('');
$('span.field-validation-valid[data-valmsg-for="Content"]').empty();
$('<div data-type="blogcomment" data-receiver-id="'+ postId +'" data-id="' + data.id + '" data-allow-edit="True" data-date="' + data.dateCreated + '" data-username="' + _this.options.authorName + '">' + comment + '</div>')
.blogcomment().appendTo(_this.subCmts);
},
url: _this.options.apictrlr
});
}
});
jQuery(function() {
$("[data-type='blogcomment']").blogcomment();
})

View file

@ -1,108 +0,0 @@
//@ts-check
if (typeof jQuery === 'undefined') {
throw new Error('This Google maps client script requires jQuery')
}
if (typeof google === 'undefined') {
throw new Error('This Google maps client script requires google')
}
(function($, maps) {
$.widget('psc.googlegeocode', {
options: {
culture: 'fr',
mapId: 'map',
longId: 'Longitude',
latId: 'Latitude',
addrValidationId: 'AddressError',
formValidId: 'ValidationSummary',
locComboId: 'LocationCombo',
specifyPlaceMsg: 'Specify a place',
GoogleDidntGeoLocalizedMsg: 'Google didn\'t reconized this address'
},
marker: null,
gmap: null,
onDragEnd: function(_this) {
// TODO reverse geo code
var npos = _this.marker.getPosition();
var nlat = Number(npos.lat());
var nlng = Number(npos.lng());
$('#' + _this.options.latId).val(nlat.toLocaleString(_this.options.culture, { minimumFractionDigits: 8 }));
$('#' + _this.options.longId).val(nlng.toLocaleString(_this.options.culture, { minimumFractionDigits: 8 }));
},
_create: function() {
var _this = this;
var scenter = { lat: parseFloat($('#' + _this.options.latId).val().replace(',', '.')),
lng: parseFloat($('#' + _this.options.longId).val().replace(',', '.')) };
this.element.addClass('googlegeocode');
this.gmap = new maps.Map(document.getElementById(this.options.mapId), {
zoom: 16,
center: scenter
});
this.marker = new maps.Marker({
map: this.gmap,
draggable: true,
animation: maps.Animation.DROP,
position: scenter
});
maps.event.addListener(this.marker, 'dragend', function() { _this.onDragEnd(_this) });
this.element.data('val-required', this.options.specifyPlaceMsg);
this.element.data('val-remote', this.options.GoogleDidntGeoLocalizedMsg);
this.element.rules('add', {
remote: {
url: 'https://maps.googleapis.com/maps/api/geocode/json',
type: 'get',
data: {
key: _this.options.mapsApiKey,
sensor: false,
address: function() {
return _this.element.val();
}
},
dataType: 'json',
dataFilter: function(datastr) {
var ul = $('#' + _this.options.locComboId);
ul.html('');
var data = JSON.parse(datastr);
data.results.forEach(function(item) {
$('<li>' + item.formatted_address + '</li>')
.data('geoloc', item)
.click(function() { _this.chooseLoc('user', item) })
.css('cursor', 'pointer')
.appendTo(ul);
});
if ((data.status === 'OK') && (data.results.length >= 1)) {
return true;
}
return false;
}
}
})
},
chooseLoc: function(sender, loc) {
var _this = this;
if (sender === 'user') this.element.val(loc.formatted_address);
var pos = loc.geometry.location;
var lat = Number(pos.lat);
var lng = Number(pos.lng);
$(document.getElementById(this.options.latId)).val(lat.toLocaleString(this.options.culture, { minimumFractionDigits: 8 }));
$(document.getElementById(this.options.longId)).val(lng.toLocaleString(this.options.culture, { minimumFractionDigits: 8 }));
this.gmap.setCenter(pos);
if (this.marker) {
this.marker.setMap(null);
}
this.marker = new maps.Marker({
map: this.gmap,
draggable: true,
animation: maps.Animation.DROP,
position: pos
});
maps.event.addListener(this.marker, 'dragend', function() { _this.onDragEnd(_this) });
this.element.valid();
$('#' + this.options.addrValidationId).empty();
$('#' + this.options.formValidId).empty();
$('#' + this.options.locComboId).empty();
return this;
}
})
})(jQuery, google.maps);

View file

@ -1,22 +0,0 @@
var allowCircleToBlog = function(e) {
var allow = $(this).prop('checked');
var circleid = $(this).data('circle-id');
var targetid = $(this).data('target-id');
var auth = { CircleId: circleid, BlogPostId: targetid };
var url = '/api/blogacl';
if (!allow) url += '/' + circleid;
console.log(auth);
$.ajax({
url: url,
type: allow ? 'POST' : 'DELETE',
data: JSON.stringify(auth),
contentType: "application/json;charset=utf-8",
success: function(data) {
console.log('auth ' + allow ? 'POSTED' : 'DELETED' + data);
},
error: function() {
console.log('Error @' + allow ? 'POSTed' : 'DELETEd');
}
});
e.preventDefault();
}

View file

@ -1,36 +0,0 @@
var markdownize = function(content) {
if (!content) return '';
var html = content.split('\n').map($.trim).filter(function(line) {
return line != '';
}).join('\n');
return toMarkdown(html);
};
var converter = new showdown.Converter();
var htmlize = function(content) {
return converter.makeHtml(content);
};
var updateMD = function(id,content) {
if (!content) return jQuery('#' + id).val('');
var markdown = markdownize(content);
if (jQuery('#' + id).val() === markdown) {
return;
}
jQuery('#' + id).val(markdown);
};
var allowDrop = function (ev) {
ev.preventDefault();
}
var drag = function (ev) {
ev.dataTransfer.setData('text', ev.target.id);
}
var drop = function (ev) {
ev.preventDefault();
var data = ev.dataTransfer.getData('text');
ev.target.appendChild(document.getElementById(data));
}

View file

@ -1,96 +0,0 @@
//
// parralax.js
//
// Author:
// Paul Schneider <paul@pschneider.fr>
//
// Copyright (c) 2015 GNU GPL
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
$(document).ready(function($){
var $window = $(window);
var $stwidth = $(window).width();
var $stheight = $(window).height();
var onPos = function (bgobj,ax,ay) {
// save pos for scrolling
tiltLR=ax;
titleFB=ay;
var speed = bgobj.data('speed');
var dx=($window.scrollLeft()+ax-$stwidth/2)/speed;
var dy=($window.scrollTop()+ay-$stheight/2)/speed;
var xPos = bgobj.attr('orgbgpx') - Math.round( dx );
var yPos = bgobj.attr('orgbgpy') - Math.round( dy );
// Put together our final background position
var coords = '' + xPos + bgobj.attr('orgbgpxu') + yPos + bgobj.attr('orgbgpyu');
// Move the background
bgobj.css({ backgroundPosition: coords });
};
var tiltLR=0;
var titleFB=0;
$('[data-type="background"]').each(function(){
var $bgobj = $(this); // assigning the object
// get the initial background position, assumes a "X% Yem" ?
var orgpos = $bgobj.css('backgroundPosition');
var bgpos = orgpos.split(" ");
var bgposx = bgpos[0];
var bgposy = bgpos[1];
if (/%$/.test(bgposx)){
bgposx = bgposx.substr(0,bgposx.length-1);
$bgobj.attr('orgbgpxu','% ');
}
else if (/em$/.test(bgposx)){
bgposx = bgposx.substr(0,bgposx.length-2);
$bgobj.attr('orgbgpxu','em ');
}
else if (/px$/.test(bgposx)){
bgposx = bgposx.substr(0,bgposx.length-2);
$bgobj.attr('orgbgpxu','px ');
}
else { $bgobj.attr('orgbgpxu','px '); }
if (/%$/.test(bgposy)){
bgposy = bgposy.substr(0,bgposy.length-1);
$bgobj.attr('orgbgpyu','% ');
}
else if (/em$/.test(bgposy)){
bgposy = bgposy.substr(0,bgposy.length-2);
$bgobj.attr('orgbgpyu','em ');
}
else if (/px$/.test(bgposy)){
bgposy = bgposy.substr(0,bgposy.length-2);
$bgobj.attr('orgbgpyu','px ');
}
else { $bgobj.attr('orgbgpyu','px '); }
$bgobj.attr('orgbgpx',parseInt(bgposx));
$bgobj.attr('orgbgpy',parseInt(bgposy));
$(window).scroll(function() {
onPos($bgobj,tiltLR,titleFB);
});
if (window.DeviceOrientationEvent) {
if ($stwidth>320 && $stheight>320) {
window.addEventListener('deviceorientation', function(event) {
onPos($bgobj,$stwidth*Math.sin(event.gamma*Math.PI/180),$stheight*Math.sin(event.beta*Math.PI/90));
},false); }
$(window).mousemove(function(e) {
onPos($bgobj,e.pageX,e.pageY);
});
}
});
}(jQuery));

View file

@ -1,33 +0,0 @@
+(function($, paypal, PAYPAL_ENV, CREATE_PAYMENT_URL, EXECUTE_PAYMENT_URL) {
$(document).ready(function() {
paypal.Button.render({
env: PAYPAL_ENV, // 'production', Optional: specify 'sandbox' environment
commit: true,
payment: function(resolve, reject) {
return paypal.request.post(CREATE_PAYMENT_URL)
.then(function(data) { resolve(data.id); })
.catch(function(err) { reject(err); });
},
onAuthorize: function(data) {
// Note: you can display a confirmation page before executing
return paypal.request.post(EXECUTE_PAYMENT_URL, { paymentID: data.paymentID, payerID: data.payerID })
.then(function(data) {
document.location = '@ViewBag.Urls.Details';
/* Go to a success page */
})
.catch(function(err) {
document.location = '/Manage/PaymentInfo/' + data.paymentID + '/?error=' + err;
/* Go to an error page */
});
}
}, '#paypal-button');
})
})(jQuery);

View file

@ -10,7 +10,7 @@ var notifClick =
};
var setUiCult = function(lngspec) {
document.cookie = 'ASPNET_CULTURE=c=' + lngspec + '|uic=' + lngspec;
document.cookie = 'ASPNETCORE_CULTURE=c=' + lngspec + '|uic=' + lngspec;
location.reload();
};

View file

@ -1,297 +0,0 @@
// requires DropZone ª toMarkdown
if (typeof window.jQuery === 'undefined') {
throw new Error('yavsc-remote-fs script requires jQuery');
}
if (typeof XMLHttpRequest === 'undefined') {
throw new Error('yavsc-remote-fs script requires XMLHttpRequest');
}
(function ($) {
'use strict';
$.widget('psc.yarfs', {
options: {
fsnurl: '/api/fs'
},
root: null,
rmDialog: null,
mvDialog: null,
flist: null,
fmlist: null,
selection: [],
curDirBar: null,
subDirsBar: null,
destination: null,
rootDisplay: null,
setRoot: function(sub) {
this.root = sub;
if (!this.root) this.rootDisplay.addClass('hidden');
else
{
this.rootDisplay.removeClass('hidden');
this.rootDisplay.html('from <code>' + this.root + '</code>');
}
},
openDir: function (sub) {
var _this = this;
this.setRoot(sub);
var owner = this.element.data('owner');
this.selection = [];
this.curDirBar.empty();
this.subDirsBar.empty();
$('<button>' + owner + '</button>')
.click(function () {
_this.openDir(null);
})
.appendTo(this.curDirBar);
var npath = null
if (_this.root) {
var dnames = _this.root.split('/');
$.each(dnames, function () {
var part = this;
if (npath == null) npath = encodeURIComponent(part);
else npath = npath + '/' + encodeURIComponent(part);
$('<button/>')
.append(part)
.click(function () {
_this.openDir(npath);
})
.appendTo(_this.curDirBar);
});
}
this.ftable.find('tr.fileinfo').remove();
var fsiourl = this.root ? '/api/fs/' + this.root : '/api/fs';
$.get(fsiourl, function (data) {
if (data.SubDirectories.length == 0 && data.Files.length == 0)
{
$('<button class="glyphicon">&#xe014; remove this empty directory</button>').click(
function() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.open('DELETE', '/api/fs/' + _this.root, true);
xmlhttp.send();
xmlhttp.onreadystatechange = function(event) {
// XMLHttpRequest.DONE === 4
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
var dnames = _this.root.split('/');
var dcnt = dnames.length;
var nroot = dnames.slice(0,dcnt-1).join('/');
_this.openDir(nroot);
}
}
}
}).appendTo(_this.subDirsBar);
}
else
{
$.each(data.SubDirectories, function () {
var item = this;
var spath = _this.root ? _this.root + '/' + encodeURIComponent(item.Name) : encodeURIComponent(item.Name);
$('<button/>')
.append(item.Name)
.click(function () {
_this.openDir(spath);
})
.appendTo(_this.subDirsBar);
});
$.each(data.Files, function () {
var item = this;
var $tr = $('<tr class="fileinfo"></tr>');
var $td = $('<td></td>');
$td.appendTo($tr);
$('<input type="checkbox" />')
.addClass('check-box')
.click(function () {
_this.SetItemSelected(item.Name, this.checked);
})
.appendTo($td);
var furl = (_this.root) ? '/files/' + owner + '/' + _this.root + '/' + encodeURIComponent(item.Name)
: '/files/' + owner + '/' + encodeURIComponent(item.Name);
$('<td class="filename"></td>')
.append($('<a></a>').attr('href',furl)
.append(item.Name)).appendTo($tr);
$('<td class="filesize">' + item.Size + '</td>').appendTo($tr);
$('<td class="filemdate">' + item.LastModified + '</td>').appendTo($tr);
$tr.appendTo(_this.ftable);
});
}
});
},
SetItemSelected: function (name, selected) {
if (selected) {
this.selection.push(name);
} else {
this.selection = this.selection.filter(function (ele) {
return ele !== name;
});
}
},
setFileAway: function(fname)
{
this.selection = this.selection.filter(function (ele) {
return ele !== fname;
});
this.ftable.find('tr.fileinfo').filter(function () {
return $(this).children('td:nth-child(2)').text() == fname;
}).remove();
},
RemoveSelectedFiles: function () {
var _this = this;
$.each(this.selection, function () {
var dfile = this;
var dfilep = _this.root ? _this.root + '/' + this : this;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function(event) {
if (this.readyState === XMLHttpRequest.DONE) {
if (this.status === 200) {
_this.setFileAway(dfile);
}
else {
alert( 'deletion of : ' + dfile + 'failed : '+ this.statusText );
}
}
};
xmlhttp.open('DELETE', '/api/fs/' + encodeURIComponent(dfilep), true);
xmlhttp.send();
});
},
moveSelectedFiles: function () {
var _this = this;
var dest = this.destination;
$.each(this.selection, function () {
var mfile = this;
var data = {};
data['id'] = _this.root ? _this.root + '/' + mfile : mfile;
data['to'] = dest;
var request = $.ajax({
url: '/api/fsc/mvftd',
type: 'POST',
data: JSON.stringify(data),
contentType: 'application/json;charset=utf-8'
});
request.done(function() {
_this.setFileAway(mfile);
});
request.fail(function( jqXHR, textStatus, msg ) {
alert( 'Failed to move : ' + mfile + ' : ' + textStatus );
});
});
},
askForRemoval: function () {
this.flist.empty();
var _this = this;
$.each(this.selection, function () {
_this.flist.append('<li>' + this + '</li>');
});
this.rmDialog.modal({ show: true });
},
askForMoving: function () {
this.fmlist.empty();
var _this = this;
$.each(this.selection, function () {
_this.fmlist.append('<li>' + this + '</li>');
});
this.mvDialog.modal({ show: true });
},
createRmDialog: function () {
var _this = this;
this.rmDialog = $('<div id="rmDialog" tabindex="-1" role="dialog"></div>');
this.rmDialog.addClass('modal');
this.rmDialog.addClass('fade');
var md = $('<div role="document"></div>');
md.addClass('modal-dialog');
this.rmDialog.append(md);
var mdCnt = $('<div class="modal-content"></div>');
mdCnt.addClass('modal-content');
var mdHeader = $('<div class="modal-header"></div>');
mdHeader.append('<h5 class="modal-title">File removal</h5>');
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
mdCnt.append(mdHeader);
var mdBody = $('<div class="modal-body"></div>');
mdBody.append('<p>You´re about to remove these files :</p>');
this.flist = $('<ul></ul>');
mdBody.append(this.flist);
mdCnt.append(mdBody);
var rmcBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do deletion</button>').click(function () {
_this.RemoveSelectedFiles();
});
var mdFooter = $('<div class="modal-footer"></div>');
mdFooter.append(rmcBtn);
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
mdCnt.append(mdFooter);
md.append(mdCnt);
this.rmDialog.appendTo(this.element);
},
onDestinationChanged: function (newDest)
{
this.destination = $(newDest).val();
},
createMvDialog: function () {
var _this = this;
this.mvDialog = $('<div id="mvDialog" tabindex="-1" role="dialog"></div>');
this.mvDialog.addClass('modal');
this.mvDialog.addClass('fade');
var md = $('<div role="document"></div>');
md.addClass('modal-dialog');
var mdCnt = $('<div class="modal-content"></div>');
mdCnt.addClass('modal-content');
var mdHeader = $('<div class="modal-header"></div>');
mdHeader.append('<h5 class="modal-title">Move files</h5>');
mdHeader.append('<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>');
mdCnt.append(mdHeader);
var mdBody = $('<div class="modal-body"></div>');
mdBody.append('<p>You´re about to move these files :</p>');
this.fmlist = $('<ul></ul>');
mdBody.append(this.fmlist);
var inputDest = $('<input type="text" class="form-control" hint="dest/dir">').on('change', function() { _this.onDestinationChanged(this); });
this.rootDisplay = $('<p></p>');
this.rootDisplay.addClass('hidden');
mdBody.append(this.rootDisplay);
var rp = $('<p>to the folowing sub-directory </p>');
mdBody.append(rp);
inputDest.appendTo(mdBody);
mdCnt.append(mdBody);
var moveBtn = $('<button type="button" data-dismiss="modal" class="btn btn-primary">Do move these files</button>').click(function () {
_this.moveSelectedFiles();
});
var mdFooter = $('<div class="modal-footer"></div>');
mdFooter.append(moveBtn);
mdFooter.append('<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>');
mdCnt.append(mdFooter);
md.append(mdCnt);
this.mvDialog.append(md);
this.mvDialog.appendTo(this.element);
},
_create: function () {
var $view = this.element;
var _this = this;
this.curDirBar = $('<div class="curdir"></div>');
this.curDirBar.appendTo($view);
this.subDirsBar = $('<div class="subdirs"></div>');
this.subDirsBar.appendTo($view);
this.ftable = $('<table>')
.css('border-spacing', '6px')
.css('border-collapse', 'separate');
var btnRm = $('<button class="glyphicon">&#xe014;</button>').click(function () {
_this.askForRemoval();
});
var btnMv = $('<button class="glyphicon">&#xe068;</button>').click(function () {
_this.askForMoving();
});
var tr = $('<tr class="fileheaders"></tr>');
_this.ftable.append(tr);
tr.append($('<th></th>').append(btnRm).append(btnMv)).append('<th>Nom</th><th>Taille</th><th>Modification</th>');
_this.ftable.appendTo($view);
this.createRmDialog();
this.createMvDialog();
this.openDir($view.data('path'));
}
});
})(window.jQuery);