mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-14 05:23:21 +00:00
Fix JS code style
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -6,278 +6,278 @@
|
||||
|
||||
(function( window ) {
|
||||
|
||||
var Selectable = function($container, options) {
|
||||
var Selectable = function($container, options) {
|
||||
|
||||
var defaults = {
|
||||
allow_multiple : false,
|
||||
selector : '',
|
||||
callbackSelection : null,
|
||||
selectStart : null,
|
||||
selectStop : null,
|
||||
limit : null
|
||||
var defaults = {
|
||||
allow_multiple : false,
|
||||
selector : '',
|
||||
callbackSelection : null,
|
||||
selectStart : null,
|
||||
selectStop : null,
|
||||
limit : null
|
||||
},
|
||||
options = (typeof options == 'object') ? options : {};
|
||||
|
||||
var $this = this;
|
||||
|
||||
if($container.data('selectionnable'))
|
||||
{
|
||||
/* this container is already selectionnable */
|
||||
if(window.console)
|
||||
{
|
||||
console.error('Trying to apply new selection to existing one');
|
||||
}
|
||||
|
||||
return $container.data('selectionnable');
|
||||
}
|
||||
|
||||
this.$container = $container;
|
||||
this.options = jQuery.extend(defaults, options);
|
||||
this.datas = new Array();
|
||||
|
||||
this.$container.data('selectionnable', this);
|
||||
this.$container.addClass('selectionnable');
|
||||
|
||||
jQuery(this.options.selector, this.$container)
|
||||
.live('click', function(event){
|
||||
|
||||
if(typeof $this.options.selectStart === 'function')
|
||||
{
|
||||
$this.options.selectStart(jQuery.extend(jQuery.Event('selectStart'), event), $this);
|
||||
}
|
||||
|
||||
var $that = jQuery(this);
|
||||
|
||||
var k = get_value($that, $this);
|
||||
|
||||
if(is_shift_key(event) && jQuery('.last_selected', this.$container).filter($this.options.selector).length != 0)
|
||||
{
|
||||
var lst = jQuery($this.options.selector, this.$container);
|
||||
|
||||
var index1 = jQuery.inArray( jQuery('.last_selected', this.$container).filter($this.options.selector)[0], lst );
|
||||
var index2 = jQuery.inArray( $that[0], lst );
|
||||
|
||||
if(index2<index1)
|
||||
{
|
||||
var tmp = index1;
|
||||
index1 = (index2 - 1) < 0 ? index2 : (index2 - 1);
|
||||
index2 = tmp;
|
||||
}
|
||||
|
||||
var stopped = false;
|
||||
|
||||
if(index2 != -1 && index1 != -1)
|
||||
{
|
||||
var exp = $this.options.selector + ':gt(' + index1 + '):lt(' + (index2-index1) + ')';
|
||||
|
||||
$.each(jQuery(exp, this.$container),function(i,n){
|
||||
if(!jQuery(n).hasClass('selected') && stopped === false)
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
var k = get_value(jQuery(n), $this);
|
||||
$this.push(k);
|
||||
jQuery(n).addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
stopped = true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if($this.has(k) === false && stopped === false)
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_ctrl_key(event))
|
||||
{
|
||||
$this.empty().push(k);
|
||||
jQuery('.selected', this.$container).filter($this.options.selector).removeClass('selected');
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this.has(k) === true)
|
||||
{
|
||||
$this.remove(k);
|
||||
$that.removeClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
jQuery('.last_selected', this.$container).removeClass('last_selected');
|
||||
$that.addClass('last_selected');
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
$this.options.selectStop(jQuery.extend(jQuery.Event('selectStop'), event), $this);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
function get_value(element, Selectable)
|
||||
{
|
||||
if(typeof Selectable.options.callbackSelection === 'function')
|
||||
{
|
||||
return Selectable.options.callbackSelection(jQuery(element));
|
||||
}
|
||||
else
|
||||
{
|
||||
return jQuery('input[name="id"]', jQuery(element)).val();
|
||||
}
|
||||
}
|
||||
|
||||
function is_ctrl_key(event)
|
||||
{
|
||||
if(event.altKey)
|
||||
return true;
|
||||
if(event.ctrlKey)
|
||||
return true;
|
||||
if(event.metaKey) // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '17') // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '224') // apple key mozilla
|
||||
return true;
|
||||
if(event.keyCode == '91') // apple key safari
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_shift_key(event)
|
||||
{
|
||||
if(event.shiftKey)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Selectable.prototype = {
|
||||
push : function(element){
|
||||
if(this.options.allow_multiple === true || !this.has(element))
|
||||
{
|
||||
this.datas.push(element);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
options = (typeof options == 'object') ? options : {};
|
||||
|
||||
var $this = this;
|
||||
|
||||
if($container.data('selectionnable'))
|
||||
{
|
||||
/* this container is already selectionnable */
|
||||
if(window.console)
|
||||
{
|
||||
console.error('Trying to apply new selection to existing one');
|
||||
}
|
||||
|
||||
return $container.data('selectionnable');
|
||||
}
|
||||
|
||||
this.$container = $container;
|
||||
this.options = jQuery.extend(defaults, options);
|
||||
this.datas = new Array();
|
||||
|
||||
this.$container.data('selectionnable', this);
|
||||
this.$container.addClass('selectionnable');
|
||||
|
||||
jQuery(this.options.selector, this.$container)
|
||||
.live('click', function(event){
|
||||
|
||||
if(typeof $this.options.selectStart === 'function')
|
||||
{
|
||||
$this.options.selectStart(jQuery.extend(jQuery.Event('selectStart'), event), $this);
|
||||
}
|
||||
|
||||
var $that = jQuery(this);
|
||||
|
||||
var k = get_value($that, $this);
|
||||
|
||||
if(is_shift_key(event) && jQuery('.last_selected', this.$container).filter($this.options.selector).length != 0)
|
||||
{
|
||||
var lst = jQuery($this.options.selector, this.$container);
|
||||
|
||||
var index1 = jQuery.inArray( jQuery('.last_selected', this.$container).filter($this.options.selector)[0], lst );
|
||||
var index2 = jQuery.inArray( $that[0], lst );
|
||||
|
||||
if(index2<index1)
|
||||
{
|
||||
var tmp = index1;
|
||||
index1 = (index2 - 1) < 0 ? index2 : (index2 - 1);
|
||||
index2 = tmp;
|
||||
}
|
||||
|
||||
var stopped = false;
|
||||
|
||||
if(index2 != -1 && index1 != -1)
|
||||
{
|
||||
var exp = $this.options.selector + ':gt(' + index1 + '):lt(' + (index2-index1) + ')';
|
||||
|
||||
$.each(jQuery(exp, this.$container),function(i,n){
|
||||
if(!jQuery(n).hasClass('selected') && stopped === false)
|
||||
hasReachLimit : function() {
|
||||
if(this.options.limit !== null && this.options.limit <= this.datas.length)
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
var k = get_value(jQuery(n), $this);
|
||||
$this.push(k);
|
||||
jQuery(n).addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
stopped = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return false;
|
||||
},
|
||||
remove : function(element){
|
||||
this.datas = jQuery.grep(this.datas, function(n){
|
||||
return(n !== element);
|
||||
});
|
||||
|
||||
if($this.has(k) === false && stopped === false)
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_ctrl_key(event))
|
||||
{
|
||||
$this.empty().push(k);
|
||||
jQuery('.selected', this.$container).filter($this.options.selector).removeClass('selected');
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this.has(k) === true)
|
||||
{
|
||||
$this.remove(k);
|
||||
$that.removeClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
return this;
|
||||
},
|
||||
has : function(element){
|
||||
|
||||
return jQuery.inArray(element,this.datas) >= 0;
|
||||
},
|
||||
get : function(){
|
||||
|
||||
return this.datas;
|
||||
},
|
||||
empty : function(){
|
||||
var $this = this;
|
||||
this.datas = new Array();
|
||||
|
||||
jQuery(this.options.selector, this.$container).filter('.selected:visible').removeClass('selected');
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
else
|
||||
|
||||
return this;
|
||||
},
|
||||
length : function(){
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
size : function(){
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
serialize : function(separator){
|
||||
|
||||
separator = separator || ';';
|
||||
|
||||
return this.datas.join(separator);
|
||||
},
|
||||
selectAll : function(){
|
||||
this.select('*');
|
||||
|
||||
return this;
|
||||
},
|
||||
select : function(selector){
|
||||
var $this = this,
|
||||
stopped = false;
|
||||
|
||||
jQuery(this.options.selector, this.$container).filter(selector).not('.selected').filter(':visible').each(function(){
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
$this.push(get_value(this, $this));
|
||||
$(this).addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(stopped === false)
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jQuery('.last_selected', this.$container).removeClass('last_selected');
|
||||
$that.addClass('last_selected');
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
$this.options.selectStop(jQuery.extend(jQuery.Event('selectStop'), event), $this);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
});
|
||||
|
||||
return;
|
||||
};
|
||||
|
||||
function get_value(element, Selectable)
|
||||
{
|
||||
if(typeof Selectable.options.callbackSelection === 'function')
|
||||
{
|
||||
return Selectable.options.callbackSelection(jQuery(element));
|
||||
}
|
||||
else
|
||||
{
|
||||
return jQuery('input[name="id"]', jQuery(element)).val();
|
||||
}
|
||||
}
|
||||
|
||||
function is_ctrl_key(event)
|
||||
{
|
||||
if(event.altKey)
|
||||
return true;
|
||||
if(event.ctrlKey)
|
||||
return true;
|
||||
if(event.metaKey) // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '17') // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '224') // apple key mozilla
|
||||
return true;
|
||||
if(event.keyCode == '91') // apple key safari
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_shift_key(event)
|
||||
{
|
||||
if(event.shiftKey)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Selectable.prototype = {
|
||||
push : function(element){
|
||||
if(this.options.allow_multiple === true || !this.has(element))
|
||||
{
|
||||
this.datas.push(element);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
hasReachLimit : function() {
|
||||
if(this.options.limit !== null && this.options.limit <= this.datas.length)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
remove : function(element){
|
||||
this.datas = jQuery.grep(this.datas, function(n){
|
||||
return(n !== element);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
has : function(element){
|
||||
|
||||
return jQuery.inArray(element,this.datas) >= 0;
|
||||
},
|
||||
get : function(){
|
||||
|
||||
return this.datas;
|
||||
},
|
||||
empty : function(){
|
||||
var $this = this;
|
||||
this.datas = new Array();
|
||||
|
||||
jQuery(this.options.selector, this.$container).filter('.selected:visible').removeClass('selected');
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
length : function(){
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
size : function(){
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
serialize : function(separator){
|
||||
|
||||
separator = separator || ';';
|
||||
|
||||
return this.datas.join(separator);
|
||||
},
|
||||
selectAll : function(){
|
||||
this.select('*');
|
||||
|
||||
return this;
|
||||
},
|
||||
select : function(selector){
|
||||
var $this = this,
|
||||
stopped = false;
|
||||
|
||||
jQuery(this.options.selector, this.$container).filter(selector).not('.selected').filter(':visible').each(function(){
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
$this.push(get_value(this, $this));
|
||||
$(this).addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(stopped === false)
|
||||
{
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
stopped = true;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
};
|
||||
|
||||
window.Selectable = Selectable;
|
||||
})(window);
|
||||
window.Selectable = Selectable;
|
||||
})(window);
|
||||
|
@@ -2,284 +2,284 @@ var p4 = p4 || {};
|
||||
|
||||
(function( window, p4, $ ) {
|
||||
|
||||
var Lists = function() {
|
||||
|
||||
};
|
||||
|
||||
var List = function (id) {
|
||||
|
||||
if(parseInt(id) <= 0)
|
||||
{
|
||||
throw 'Invalid list id';
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
this.id = id;
|
||||
};
|
||||
|
||||
Lists.prototype = {
|
||||
create : function(name, callback){
|
||||
|
||||
var $this = this;
|
||||
List.prototype = {
|
||||
addUsers : function(arrayUsers, callback) {
|
||||
|
||||
$.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')
|
||||
if(!arrayUsers instanceof Array)
|
||||
{
|
||||
var list = new List(data.list_id);
|
||||
callback(list);
|
||||
throw 'addUsers takes array as argument';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
humane.error(data.message);
|
||||
}
|
||||
|
||||
var $this = this;
|
||||
var data = {usr_ids : $(arrayUsers).toArray()};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + $this.id + '/add/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
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);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
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;
|
||||
var data = {usr_ids : $(arrayUsers).toArray()};
|
||||
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + $this.id + '/add/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
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;
|
||||
p4.Lists = new Lists();
|
||||
document.List = List;
|
||||
|
||||
$.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);
|
||||
})(document, p4, jQuery);
|
||||
|
Reference in New Issue
Block a user