mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 20:43:25 +00:00
Push javascript
This commit is contained in:
284
www/include/js/jquery.lists.js
Normal file
284
www/include/js/jquery.lists.js
Normal file
@@ -0,0 +1,284 @@
|
||||
var p4 = p4 || {};
|
||||
|
||||
(function( window, p4, $ ) {
|
||||
|
||||
var Lists = function() {
|
||||
|
||||
};
|
||||
|
||||
var List = function (id) {
|
||||
|
||||
if(parseInt(id) <= 0)
|
||||
{
|
||||
throw 'Invalid list id';
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
};
|
||||
|
||||
Lists.prototype = {
|
||||
create : function(name, callback){
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/',
|
||||
dataType: 'json',
|
||||
data: {name : name},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
var list = new List(data.list_id);
|
||||
callback(list);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
get : function(callback, type) {
|
||||
|
||||
var $this = this;
|
||||
type = typeof type === 'undefined' ? 'json' : type;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/prod/lists/all/',
|
||||
dataType: type,
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(type == 'json')
|
||||
{
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback(data.result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
List.prototype = {
|
||||
addUsers : function(arrayUsers, callback) {
|
||||
|
||||
if(!arrayUsers instanceof Array)
|
||||
{
|
||||
throw 'addUsers takes array as argument';
|
||||
}
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/add/',
|
||||
dataType: 'json',
|
||||
data: {usr_ids : arrayUsers},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
addUser : function(usr_id, callback) {
|
||||
this.addUsers([usr_id], callback);
|
||||
},
|
||||
remove : function(callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/delete/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
update : function(name, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/update/',
|
||||
dataType: 'json',
|
||||
data: { name : name },
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
removeUser : function(usr_id, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/remove/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
shareWith : function(usr_id, role, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/share/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {role : role},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
unshareWith : function(callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/unshare/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
get : function(callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: '/prod/lists/list/' + this.id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
p4.Lists = new Lists();
|
||||
document.List = List;
|
||||
|
||||
})(document, p4, jQuery);
|
Reference in New Issue
Block a user