mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 21:13:26 +00:00
Fix JS codestyle
This commit is contained in:
@@ -1,47 +1,45 @@
|
||||
(function (window) {
|
||||
|
||||
(function( window ) {
|
||||
|
||||
function checkVocabId(VocabularyId)
|
||||
{
|
||||
if(typeof VocabularyId === 'undefined')
|
||||
function checkVocabId(VocabularyId) {
|
||||
if (typeof VocabularyId === 'undefined')
|
||||
VocabularyId = null;
|
||||
|
||||
if(VocabularyId === '')
|
||||
if (VocabularyId === '')
|
||||
VocabularyId = null;
|
||||
|
||||
return VocabularyId;
|
||||
}
|
||||
|
||||
var recordFieldValue = function(meta_id, value, VocabularyId) {
|
||||
var recordFieldValue = function (meta_id, value, VocabularyId) {
|
||||
|
||||
VocabularyId = checkVocabId(VocabularyId);
|
||||
|
||||
this.datas = {
|
||||
meta_id:meta_id,
|
||||
value:value,
|
||||
VocabularyId:VocabularyId
|
||||
meta_id: meta_id,
|
||||
value: value,
|
||||
VocabularyId: VocabularyId
|
||||
};
|
||||
|
||||
var $this = this;
|
||||
};
|
||||
|
||||
recordFieldValue.prototype = {
|
||||
getValue : function() {
|
||||
getValue: function () {
|
||||
return this.datas.value;
|
||||
},
|
||||
getMetaId : function() {
|
||||
getMetaId: function () {
|
||||
return this.datas.meta_id;
|
||||
},
|
||||
getVocabularyId : function() {
|
||||
getVocabularyId: function () {
|
||||
return this.datas.VocabularyId;
|
||||
},
|
||||
setValue : function(value, VocabularyId) {
|
||||
setValue: function (value, VocabularyId) {
|
||||
|
||||
this.datas.value = value;
|
||||
this.datas.VocabularyId = checkVocabId(VocabularyId);
|
||||
return this;
|
||||
},
|
||||
remove : function() {
|
||||
remove: function () {
|
||||
this.datas.value = '';
|
||||
this.datas.VocabularyId = null;
|
||||
|
||||
@@ -49,23 +47,22 @@
|
||||
}
|
||||
};
|
||||
|
||||
var databoxField = function(name, label, meta_struct_id, options) {
|
||||
var databoxField = function (name, label, meta_struct_id, options) {
|
||||
|
||||
var defaults = {
|
||||
multi : false,
|
||||
required : false,
|
||||
readonly : false,
|
||||
maxLength : null,
|
||||
minLength : null,
|
||||
type : 'string',
|
||||
separator : null,
|
||||
vocabularyControl : null,
|
||||
vocabularyRestricted : false
|
||||
multi: false,
|
||||
required: false,
|
||||
readonly: false,
|
||||
maxLength: null,
|
||||
minLength: null,
|
||||
type: 'string',
|
||||
separator: null,
|
||||
vocabularyControl: null,
|
||||
vocabularyRestricted: false
|
||||
},
|
||||
options = (typeof options == 'object') ? options : {};
|
||||
|
||||
if(isNaN(meta_struct_id))
|
||||
{
|
||||
if (isNaN(meta_struct_id)) {
|
||||
throw 'meta_struct_id should be a number';
|
||||
}
|
||||
|
||||
@@ -74,93 +71,83 @@
|
||||
this.meta_struct_id = meta_struct_id;
|
||||
this.options = jQuery.extend(defaults, options);
|
||||
|
||||
if(this.options.multi === true && this.options.separator === null)
|
||||
{
|
||||
if (this.options.multi === true && this.options.separator === null) {
|
||||
this.options.separator = ';';
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
databoxField.prototype = {
|
||||
getMetaStructId : function() {
|
||||
getMetaStructId: function () {
|
||||
return this.meta_struct_id;
|
||||
},
|
||||
getName : function() {
|
||||
getName: function () {
|
||||
return this.name;
|
||||
},
|
||||
getLabel : function() {
|
||||
getLabel: function () {
|
||||
return this.label;
|
||||
},
|
||||
isMulti : function() {
|
||||
isMulti: function () {
|
||||
return this.options.multi;
|
||||
},
|
||||
isRequired : function() {
|
||||
isRequired: function () {
|
||||
return this.options.required;
|
||||
},
|
||||
isReadonly : function() {
|
||||
isReadonly: function () {
|
||||
return this.options.readonly;
|
||||
},
|
||||
getMaxLength : function() {
|
||||
getMaxLength: function () {
|
||||
return this.options.maxLength;
|
||||
},
|
||||
getMinLength : function() {
|
||||
getMinLength: function () {
|
||||
return this.options.minLength;
|
||||
},
|
||||
getType : function() {
|
||||
getType: function () {
|
||||
return this.options.type;
|
||||
},
|
||||
getSeparator : function() {
|
||||
getSeparator: function () {
|
||||
return this.options.separator;
|
||||
}
|
||||
};
|
||||
|
||||
var recordField = function(databoxField, arrayValues) {
|
||||
var recordField = function (databoxField, arrayValues) {
|
||||
|
||||
this.databoxField = databoxField;
|
||||
this.options = {
|
||||
dirty : false
|
||||
dirty: false
|
||||
};
|
||||
this.datas = new Array();
|
||||
|
||||
if(arrayValues instanceof Array)
|
||||
{
|
||||
if(arrayValues.length > 1 && !databoxField.isMulti())
|
||||
if (arrayValues instanceof Array) {
|
||||
if (arrayValues.length > 1 && !databoxField.isMulti())
|
||||
throw 'You can not add multiple values to a non multi field ' + databoxField.getName();
|
||||
|
||||
var first = true;
|
||||
|
||||
for(v in arrayValues)
|
||||
{
|
||||
if(typeof arrayValues[v] !== 'object')
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
for (v in arrayValues) {
|
||||
if (typeof arrayValues[v] !== 'object') {
|
||||
if (window.console) {
|
||||
console.error('Trying to add a non-recordFieldValue to the field...');
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(isNaN(arrayValues[v].getMetaId()))
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (isNaN(arrayValues[v].getMetaId())) {
|
||||
if (window.console) {
|
||||
console.error('Trying to add a recordFieldValue without metaId...');
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!first && this.options.multi === false)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (!first && this.options.multi === false) {
|
||||
if (window.console) {
|
||||
console.error('Trying to add multi values in a non-multi field');
|
||||
}
|
||||
}
|
||||
|
||||
if(window.console)
|
||||
{
|
||||
if (window.console) {
|
||||
console.log('adding a value : ', arrayValues[v]);
|
||||
}
|
||||
|
||||
@@ -172,101 +159,81 @@
|
||||
var $this = this;
|
||||
}
|
||||
recordField.prototype = {
|
||||
getName : function() {
|
||||
getName: function () {
|
||||
return this.databoxField.getName();
|
||||
},
|
||||
getMetaStructId : function() {
|
||||
getMetaStructId: function () {
|
||||
return this.databoxField.getMetaStructId();
|
||||
},
|
||||
isMulti : function() {
|
||||
isMulti: function () {
|
||||
return this.databoxField.isMulti();
|
||||
},
|
||||
isRequired : function() {
|
||||
isRequired: function () {
|
||||
return this.databoxField.isRequired();
|
||||
},
|
||||
isDirty : function() {
|
||||
isDirty: function () {
|
||||
return this.options.dirty;
|
||||
},
|
||||
addValue : function(value, merge, VocabularyId) {
|
||||
addValue: function (value, merge, VocabularyId) {
|
||||
|
||||
VocabularyId = checkVocabId(VocabularyId);
|
||||
|
||||
merge = !!merge;
|
||||
|
||||
if(this.databoxField.isReadonly())
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (this.databoxField.isReadonly()) {
|
||||
if (window.console) {
|
||||
console.error('Unable to set a value to a readonly field');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if(window.console)
|
||||
{
|
||||
console.log('adding value ',value,' vocId : ', VocabularyId , ' ; merge is ',merge);
|
||||
if (window.console) {
|
||||
console.log('adding value ', value, ' vocId : ', VocabularyId, ' ; merge is ', merge);
|
||||
}
|
||||
|
||||
if(this.isMulti())
|
||||
{
|
||||
if(!this.hasValue(value, VocabularyId))
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
console.log('adding new multi value ',value);
|
||||
if (this.isMulti()) {
|
||||
if (!this.hasValue(value, VocabularyId)) {
|
||||
if (window.console) {
|
||||
console.log('adding new multi value ', value);
|
||||
}
|
||||
this.datas.push(new recordFieldValue(null, value, VocabularyId));
|
||||
this.options.dirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
console.log('already have ',value);
|
||||
else {
|
||||
if (window.console) {
|
||||
console.log('already have ', value);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(merge === true && this.isEmpty() === false && VocabularyId === null)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
console.log('Merging value ',value);
|
||||
else {
|
||||
if (merge === true && this.isEmpty() === false && VocabularyId === null) {
|
||||
if (window.console) {
|
||||
console.log('Merging value ', value);
|
||||
}
|
||||
this.datas[0].setValue(this.datas[0].getValue() + ' ' + value, VocabularyId);
|
||||
|
||||
this.options.dirty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(merge === true && this.isEmpty() === false && VocabularyId !== null)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
else {
|
||||
if (merge === true && this.isEmpty() === false && VocabularyId !== null) {
|
||||
if (window.console) {
|
||||
console.error('Cannot merge vocabularies');
|
||||
}
|
||||
this.datas[0].setValue(value, VocabularyId);
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
|
||||
if(!this.hasValue(value, VocabularyId))
|
||||
{
|
||||
if(this.datas.length === 0)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
console.log('Adding new value ',value);
|
||||
if (!this.hasValue(value, VocabularyId)) {
|
||||
if (this.datas.length === 0) {
|
||||
if (window.console) {
|
||||
console.log('Adding new value ', value);
|
||||
}
|
||||
this.datas.push(new recordFieldValue(null, value, VocabularyId));
|
||||
}
|
||||
else
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
console.log('Updating value ',value);
|
||||
else {
|
||||
if (window.console) {
|
||||
console.log('Updating value ', value);
|
||||
}
|
||||
this.datas[0].setValue(value, VocabularyId);
|
||||
}
|
||||
@@ -278,35 +245,27 @@
|
||||
|
||||
return this;
|
||||
},
|
||||
hasValue : function(value, VocabularyId) {
|
||||
hasValue: function (value, VocabularyId) {
|
||||
|
||||
if(typeof value === 'undefined')
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (typeof value === 'undefined') {
|
||||
if (window.console) {
|
||||
console.error('Trying to check the presence of an undefined value');
|
||||
}
|
||||
}
|
||||
|
||||
VocabularyId = checkVocabId(VocabularyId);
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
if(VocabularyId !== null)
|
||||
{
|
||||
if(this.datas[d].getVocabularyId() === VocabularyId)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
for (d in this.datas) {
|
||||
if (VocabularyId !== null) {
|
||||
if (this.datas[d].getVocabularyId() === VocabularyId) {
|
||||
if (window.console) {
|
||||
console.log('already got the vocab ID');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(this.datas[d].getVocabularyId() === null && this.datas[d].getValue() == value)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
else if (this.datas[d].getVocabularyId() === null && this.datas[d].getValue() == value) {
|
||||
if (window.console) {
|
||||
console.log('already got this value');
|
||||
}
|
||||
return true;
|
||||
@@ -314,12 +273,10 @@
|
||||
}
|
||||
return false;
|
||||
},
|
||||
removeValue : function(value, vocabularyId) {
|
||||
removeValue: function (value, vocabularyId) {
|
||||
|
||||
if(this.databoxField.isReadonly())
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (this.databoxField.isReadonly()) {
|
||||
if (window.console) {
|
||||
console.error('Unable to set a value to a readonly field');
|
||||
}
|
||||
|
||||
@@ -328,33 +285,25 @@
|
||||
|
||||
vocabularyId = checkVocabId(vocabularyId);
|
||||
|
||||
if(window.console)
|
||||
{
|
||||
if (window.console) {
|
||||
console.log('Try to remove value ', value, vocabularyId, this.datas);
|
||||
}
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
for (d in this.datas) {
|
||||
if (window.console) {
|
||||
console.log('loopin... ', this.datas[d].getValue());
|
||||
}
|
||||
if(this.datas[d].getVocabularyId() !== null)
|
||||
{
|
||||
if(this.datas[d].getVocabularyId() == vocabularyId)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (this.datas[d].getVocabularyId() !== null) {
|
||||
if (this.datas[d].getVocabularyId() == vocabularyId) {
|
||||
if (window.console) {
|
||||
console.log('Found within the vocab ! removing... ');
|
||||
}
|
||||
this.datas[d].remove();
|
||||
this.options.dirty = true;
|
||||
}
|
||||
}
|
||||
else if(this.datas[d].getValue() == value)
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
else if (this.datas[d].getValue() == value) {
|
||||
if (window.console) {
|
||||
console.log('Found ! removing... ');
|
||||
}
|
||||
this.datas[d].remove();
|
||||
@@ -363,60 +312,54 @@
|
||||
}
|
||||
return this;
|
||||
},
|
||||
isEmpty : function() {
|
||||
isEmpty: function () {
|
||||
var empty = true;
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
if(this.datas[d].getValue() !== '')
|
||||
for (d in this.datas) {
|
||||
if (this.datas[d].getValue() !== '')
|
||||
empty = false;
|
||||
}
|
||||
return empty;
|
||||
},
|
||||
empty : function() {
|
||||
empty: function () {
|
||||
|
||||
if(this.databoxField.isReadonly())
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (this.databoxField.isReadonly()) {
|
||||
if (window.console) {
|
||||
console.error('Unable to set a value to a readonly field');
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
for (d in this.datas) {
|
||||
this.datas[d].remove();
|
||||
this.options.dirty = true;
|
||||
}
|
||||
return this;
|
||||
},
|
||||
getValue : function() {
|
||||
getValue: function () {
|
||||
|
||||
if(this.isMulti())
|
||||
if (this.isMulti())
|
||||
throw 'This field is multi, I can not give you a single value';
|
||||
|
||||
if(this.isEmpty())
|
||||
if (this.isEmpty())
|
||||
return null;
|
||||
|
||||
return this.datas[0];
|
||||
},
|
||||
getValues : function() {
|
||||
getValues: function () {
|
||||
|
||||
if(!this.isMulti())
|
||||
{
|
||||
if (!this.isMulti()) {
|
||||
throw 'This field is not multi, I can not give you multiple values';
|
||||
}
|
||||
|
||||
if(this.isEmpty())
|
||||
if (this.isEmpty())
|
||||
return new Array();
|
||||
|
||||
var arrayValues = [];
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
if(this.datas[d].getValue() === '')
|
||||
for (d in this.datas) {
|
||||
if (this.datas[d].getValue() === '')
|
||||
continue;
|
||||
|
||||
arrayValues.push(this.datas[d]);
|
||||
@@ -424,29 +367,26 @@
|
||||
|
||||
return arrayValues;
|
||||
},
|
||||
sort : function(algo) {
|
||||
sort: function (algo) {
|
||||
this.datas.sort(algo);
|
||||
|
||||
return this;
|
||||
},
|
||||
getSerializedValues : function() {
|
||||
getSerializedValues: function () {
|
||||
|
||||
var arrayValues = [];
|
||||
var values = this.getValues();
|
||||
|
||||
for(v in values)
|
||||
{
|
||||
for (v in values) {
|
||||
arrayValues.push(values[v].getValue());
|
||||
}
|
||||
|
||||
return arrayValues.join(' ' + this.databoxField.getSeparator() + ' ');
|
||||
},
|
||||
replaceValue : function(search, replace) {
|
||||
replaceValue: function (search, replace) {
|
||||
|
||||
if(this.databoxField.isReadonly())
|
||||
{
|
||||
if(window.console)
|
||||
{
|
||||
if (this.databoxField.isReadonly()) {
|
||||
if (window.console) {
|
||||
console.error('Unable to set a value to a readonly field');
|
||||
}
|
||||
|
||||
@@ -455,18 +395,15 @@
|
||||
|
||||
var n = 0;
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
if(this.datas[d].getVocabularyId() !== null)
|
||||
{
|
||||
for (d in this.datas) {
|
||||
if (this.datas[d].getVocabularyId() !== null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var value = this.datas[d].getValue();
|
||||
var replacedValue = value.replace(search, replace);
|
||||
|
||||
if(value === replacedValue)
|
||||
{
|
||||
if (value === replacedValue) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -474,8 +411,7 @@
|
||||
|
||||
this.removeValue(value);
|
||||
|
||||
if(!this.hasValue(replacedValue))
|
||||
{
|
||||
if (!this.hasValue(replacedValue)) {
|
||||
this.addValue(replacedValue);
|
||||
}
|
||||
|
||||
@@ -484,20 +420,18 @@
|
||||
|
||||
return n;
|
||||
},
|
||||
exportDatas : function() {
|
||||
exportDatas: function () {
|
||||
|
||||
var returnValue = new Array();
|
||||
|
||||
for(d in this.datas)
|
||||
{
|
||||
for (d in this.datas) {
|
||||
var temp = {
|
||||
meta_id : this.datas[d].getMetaId() ? this.datas[d].getMetaId() : '',
|
||||
meta_struct_id : this.getMetaStructId(),
|
||||
value : this.datas[d].getValue()
|
||||
meta_id: this.datas[d].getMetaId() ? this.datas[d].getMetaId() : '',
|
||||
meta_struct_id: this.getMetaStructId(),
|
||||
value: this.datas[d].getValue()
|
||||
};
|
||||
|
||||
if(this.datas[d].getVocabularyId())
|
||||
{
|
||||
if (this.datas[d].getVocabularyId()) {
|
||||
temp.vocabularyId = this.datas[d].getVocabularyId();
|
||||
}
|
||||
returnValue.push(temp);
|
||||
|
@@ -4,27 +4,25 @@
|
||||
*
|
||||
*/
|
||||
|
||||
(function( window ) {
|
||||
(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
|
||||
allow_multiple: false,
|
||||
selector: '',
|
||||
callbackSelection: null,
|
||||
selectStart: null,
|
||||
selectStop: null,
|
||||
limit: null
|
||||
},
|
||||
options = (typeof options == 'object') ? options : {};
|
||||
|
||||
var $this = this;
|
||||
|
||||
if($container.data('selectionnable'))
|
||||
{
|
||||
if ($container.data('selectionnable')) {
|
||||
/* this container is already selectionnable */
|
||||
if(window.console)
|
||||
{
|
||||
if (window.console) {
|
||||
console.error('Trying to apply new selection to existing one');
|
||||
}
|
||||
|
||||
@@ -39,10 +37,9 @@
|
||||
this.$container.addClass('selectionnable');
|
||||
|
||||
jQuery(this.options.selector, this.$container)
|
||||
.live('click', function(event){
|
||||
.live('click', function (event) {
|
||||
|
||||
if(typeof $this.options.selectStart === 'function')
|
||||
{
|
||||
if (typeof $this.options.selectStart === 'function') {
|
||||
$this.options.selectStart(jQuery.extend(jQuery.Event('selectStart'), event), $this);
|
||||
}
|
||||
|
||||
@@ -50,15 +47,13 @@
|
||||
|
||||
var k = get_value($that, $this);
|
||||
|
||||
if(is_shift_key(event) && jQuery('.last_selected', this.$container).filter($this.options.selector).length != 0)
|
||||
{
|
||||
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 );
|
||||
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)
|
||||
{
|
||||
if (index2 < index1) {
|
||||
var tmp = index1;
|
||||
index1 = (index2 - 1) < 0 ? index2 : (index2 - 1);
|
||||
index2 = tmp;
|
||||
@@ -66,21 +61,17 @@
|
||||
|
||||
var stopped = false;
|
||||
|
||||
if(index2 != -1 && index1 != -1)
|
||||
{
|
||||
var exp = $this.options.selector + ':gt(' + index1 + '):lt(' + (index2-index1) + ')';
|
||||
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())
|
||||
{
|
||||
$.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
|
||||
{
|
||||
else {
|
||||
alert(language.max_record_selected);
|
||||
stopped = true;
|
||||
}
|
||||
@@ -88,43 +79,33 @@
|
||||
});
|
||||
}
|
||||
|
||||
if($this.has(k) === false && stopped === false)
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
if ($this.has(k) === false && stopped === false) {
|
||||
if (!$this.hasReachLimit()) {
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!is_ctrl_key(event))
|
||||
{
|
||||
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)
|
||||
{
|
||||
else {
|
||||
if ($this.has(k) === true) {
|
||||
$this.remove(k);
|
||||
$that.removeClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this.hasReachLimit())
|
||||
{
|
||||
else {
|
||||
if (!$this.hasReachLimit()) {
|
||||
$this.push(k);
|
||||
$that.addClass('selected');
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
}
|
||||
@@ -135,8 +116,7 @@
|
||||
$that.addClass('last_selected');
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
if (typeof $this.options.selectStop === 'function') {
|
||||
$this.options.selectStop(jQuery.extend(jQuery.Event('selectStop'), event), $this);
|
||||
}
|
||||
|
||||
@@ -147,122 +127,110 @@
|
||||
return;
|
||||
};
|
||||
|
||||
function get_value(element, Selectable)
|
||||
{
|
||||
if(typeof Selectable.options.callbackSelection === 'function')
|
||||
{
|
||||
function get_value(element, Selectable) {
|
||||
if (typeof Selectable.options.callbackSelection === 'function') {
|
||||
return Selectable.options.callbackSelection(jQuery(element));
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
return jQuery('input[name="id"]', jQuery(element)).val();
|
||||
}
|
||||
}
|
||||
|
||||
function is_ctrl_key(event)
|
||||
{
|
||||
if(event.altKey)
|
||||
function is_ctrl_key(event) {
|
||||
if (event.altKey)
|
||||
return true;
|
||||
if(event.ctrlKey)
|
||||
if (event.ctrlKey)
|
||||
return true;
|
||||
if(event.metaKey) // apple key opera
|
||||
if (event.metaKey) // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '17') // apple key opera
|
||||
if (event.keyCode == '17') // apple key opera
|
||||
return true;
|
||||
if(event.keyCode == '224') // apple key mozilla
|
||||
if (event.keyCode == '224') // apple key mozilla
|
||||
return true;
|
||||
if(event.keyCode == '91') // apple key safari
|
||||
if (event.keyCode == '91') // apple key safari
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function is_shift_key(event)
|
||||
{
|
||||
if(event.shiftKey)
|
||||
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))
|
||||
{
|
||||
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)
|
||||
{
|
||||
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){
|
||||
remove: function (element) {
|
||||
this.datas = jQuery.grep(this.datas, function (n) {
|
||||
return(n !== element);
|
||||
});
|
||||
|
||||
return this;
|
||||
},
|
||||
has : function(element){
|
||||
has: function (element) {
|
||||
|
||||
return jQuery.inArray(element,this.datas) >= 0;
|
||||
return jQuery.inArray(element, this.datas) >= 0;
|
||||
},
|
||||
get : function(){
|
||||
get: function () {
|
||||
|
||||
return this.datas;
|
||||
},
|
||||
empty : function(){
|
||||
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')
|
||||
{
|
||||
if (typeof $this.options.selectStop === 'function') {
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
|
||||
return this;
|
||||
},
|
||||
length : function(){
|
||||
length: function () {
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
size : function(){
|
||||
size: function () {
|
||||
|
||||
return this.datas.length;
|
||||
},
|
||||
serialize : function(separator){
|
||||
serialize: function (separator) {
|
||||
|
||||
separator = separator || ';';
|
||||
|
||||
return this.datas.join(separator);
|
||||
},
|
||||
selectAll : function(){
|
||||
selectAll: function () {
|
||||
this.select('*');
|
||||
|
||||
return this;
|
||||
},
|
||||
select : function(selector){
|
||||
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())
|
||||
{
|
||||
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)
|
||||
{
|
||||
else {
|
||||
if (stopped === false) {
|
||||
alert(language.max_record_selected);
|
||||
}
|
||||
stopped = true;
|
||||
@@ -270,8 +238,7 @@
|
||||
});
|
||||
|
||||
|
||||
if(typeof $this.options.selectStop === 'function')
|
||||
{
|
||||
if (typeof $this.options.selectStop === 'function') {
|
||||
$this.options.selectStop(jQuery.Event('selectStop'), $this);
|
||||
}
|
||||
|
||||
|
@@ -1,15 +1,14 @@
|
||||
var p4 = p4 || {};
|
||||
|
||||
(function( window, p4, $ ) {
|
||||
(function (window, p4, $) {
|
||||
|
||||
var Lists = function() {
|
||||
var Lists = function () {
|
||||
|
||||
};
|
||||
|
||||
var List = function (id) {
|
||||
|
||||
if(parseInt(id) <= 0)
|
||||
{
|
||||
if (parseInt(id) <= 0) {
|
||||
throw 'Invalid list id';
|
||||
}
|
||||
|
||||
@@ -17,7 +16,7 @@ var p4 = p4 || {};
|
||||
};
|
||||
|
||||
Lists.prototype = {
|
||||
create : function(name, callback){
|
||||
create: function (name, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -25,27 +24,24 @@ var p4 = p4 || {};
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/',
|
||||
dataType: 'json',
|
||||
data: {name : name},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
data: {name: name},
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
var list = new List(data.list_id);
|
||||
callback(list);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
},
|
||||
get : function(callback, type) {
|
||||
get: function (callback, type) {
|
||||
|
||||
var $this = this;
|
||||
type = typeof type === 'undefined' ? 'json' : type;
|
||||
@@ -55,27 +51,21 @@ var p4 = p4 || {};
|
||||
url: '/prod/lists/all/',
|
||||
dataType: type,
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(type == 'json')
|
||||
{
|
||||
if(data.success)
|
||||
{
|
||||
success: function (data) {
|
||||
if (type == 'json') {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback(data.result);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
else {
|
||||
if (typeof callback === 'function') {
|
||||
callback(data);
|
||||
}
|
||||
}
|
||||
@@ -86,42 +76,38 @@ var p4 = p4 || {};
|
||||
}
|
||||
|
||||
List.prototype = {
|
||||
addUsers : function(arrayUsers, callback) {
|
||||
addUsers: function (arrayUsers, callback) {
|
||||
|
||||
if(!arrayUsers instanceof Array)
|
||||
{
|
||||
if (!arrayUsers instanceof Array) {
|
||||
throw 'addUsers takes array as argument';
|
||||
}
|
||||
|
||||
var $this = this;
|
||||
var data = {usr_ids : $(arrayUsers).toArray()};
|
||||
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)
|
||||
{
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
addUser : function(usr_id, callback) {
|
||||
addUser: function (usr_id, callback) {
|
||||
this.addUsers([usr_id], callback);
|
||||
},
|
||||
remove : function(callback) {
|
||||
remove: function (callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -130,24 +116,21 @@ var p4 = p4 || {};
|
||||
url: '/prod/lists/list/' + this.id + '/delete/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
update : function(name, callback) {
|
||||
update: function (name, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -155,25 +138,22 @@ var p4 = p4 || {};
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/update/',
|
||||
dataType: 'json',
|
||||
data: { name : name },
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
data: { name: name },
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
removeUser : function(usr_id, callback) {
|
||||
removeUser: function (usr_id, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -182,24 +162,21 @@ var p4 = p4 || {};
|
||||
url: '/prod/lists/list/' + this.id + '/remove/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
shareWith : function(usr_id, role, callback) {
|
||||
shareWith: function (usr_id, role, callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -207,25 +184,22 @@ var p4 = p4 || {};
|
||||
type: 'POST',
|
||||
url: '/prod/lists/list/' + this.id + '/share/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {role : role},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
data: {role: role},
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
unshareWith : function(callback) {
|
||||
unshareWith: function (callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -234,24 +208,21 @@ var p4 = p4 || {};
|
||||
url: '/prod/lists/list/' + this.id + '/unshare/' + usr_id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
get : function(callback) {
|
||||
get: function (callback) {
|
||||
|
||||
var $this = this;
|
||||
|
||||
@@ -260,18 +231,15 @@ var p4 = p4 || {};
|
||||
url: '/prod/lists/list/' + this.id + '/',
|
||||
dataType: 'json',
|
||||
data: {},
|
||||
success: function(data){
|
||||
if(data.success)
|
||||
{
|
||||
success: function (data) {
|
||||
if (data.success) {
|
||||
humane.info(data.message);
|
||||
|
||||
if(typeof callback === 'function')
|
||||
{
|
||||
if (typeof callback === 'function') {
|
||||
callback($this, data);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
else {
|
||||
humane.error(data.message);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user