forked from Aymkdn/SharepointPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsharepointplus-3.0.10.min.js
10 lines (10 loc) · 73.6 KB
/
sharepointplus-3.0.10.min.js
1
2
3
4
5
6
7
8
9
10
/*!
* SharepointPlus v3.0.10
* Copyright 2014, Aymeric (@aymkdn)
* Contact: http://kodono.info
* Documentation: http://aymkdn.github.com/SharepointPlus/
* License: GPL v2 (http://aymkdn.github.com/SharepointPlus/license.txt)
*/
Array.prototype.indexOf||(Array.prototype.indexOf=function(e){"use strict";if(null==this)throw new TypeError;var t=Object(this),r=t.length>>>0;if(0===r)return-1;var s=0;if(arguments.length>1&&(s=Number(arguments[1]),s!=s?s=0:0!=s&&1/0!=s&&s!=-1/0&&(s=(s>0||-1)*Math.floor(Math.abs(s)))),s>=r)return-1;for(var i=s>=0?s:Math.max(r-Math.abs(s),0);r>i;i++)if(i in t&&t[i]===e)return i;return-1}),String.prototype.trim||(String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g,"")});var _SP_b64_encode=function(e,t,r,s,i,o){for(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r="=",s=o="";i&=3,e.charAt(s++)||(t="=",i);o+=t.charAt(63&r>>2*++i))r=r<<8|e.charCodeAt(s-=!i);return o};_SP_APPROVED=0,_SP_REJECTED=1,_SP_PENDING=2,_SP_DRAFT=3,_SP_SCHEDULED=4,_SP_CACHE_FORMFIELDS=null,__SP_NOTIFY_READY=!1,__SP_NOTIFY_QUEUE=[],__SP_NOTIFY=[],"function"==typeof jQuery&&$(".ms-lookuptypeintextbox").each(function(){for(var e=$(this),t=$("#"+e.attr("optHid")).val(),r=e.attr("choices").split("|"),s='<select id="'+e.attr("id")+'_Lookup" name="'+e.attr("name").replace(/\_/g,"$")+'" data-info="This SELECT has been created by SharepointPlus" title="'+e.attr("title")+'">',i=0;i<r.length;i+=2)s+='<option value="'+r[i+1]+'"'+(r[i+1]==t?' selected="selected"':"")+">"+r[i]+"</option>";s+="</select>",e.closest("span").hide().before(s),$("#"+e.attr("id")+"_Lookup").on("change",function(){var e=$("#"+$(this).attr("id").slice(0,-7)),t=$("#"+e.attr("optHid")),r=$(this).val();t.val(r),e.val($(this).find("option[value='"+("0"!==r?r:"")+"']").text())}).trigger("change")}),function(window){function SharepointPlus(){return this instanceof arguments.callee?void 0:new arguments.callee}var fastMap=function(e,t){for(var r=e.length,s=new Array(r),i=r/8,o=r%8,n=r-1;n>-1;n--){var a=i,l=o;do{switch(l){case 0:s[n]=t(e[n]),n--;case 7:s[n]=t(e[n]),n--;case 6:s[n]=t(e[n]),n--;case 5:s[n]=t(e[n]),n--;case 4:s[n]=t(e[n]),n--;case 3:s[n]=t(e[n]),n--;case 2:s[n]=t(e[n]),n--;case 1:s[n]=t(e[n]),n--}l=0}while(--a>0)}return s},decode_b64=function(e,t,r,s,i,o,n){for(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",i=o=n="";r=e.charAt(n++);~r&&(s=o%4?64*s+r:r,o++%4)?i+=String.fromCharCode(255&s>>(-2*o&6)):0)r=t.indexOf(r);return i},encode_b64=function(e,t,r,s,i,o){for(t="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",r="=",s=o="";i&=3,e.charAt(s++)||(t="=",i);o+=t.charAt(63&r>>2*++i))r=r<<8|e.charCodeAt(s-=!i);return o};SharepointPlus.prototype={data:[],length:0,listQueue:[],needQueue:!1,getVersion:function(){return"3.0.10"},list:function(e,t){return this.reset(),t?("/"===t.substring(t.length-1,t.length)&&(t=t.substring(0,t.length-1)),this.url=t):this._getURL(),this.listID=e.replace(/&/g,"&"),this},_getURL:function(){if(void 0===this.url&&"undefined"==typeof L_Menu_BaseUrl&&void 0===jQuery("body").data("sp-currenturl")){this.needQueue=!0;var e=this,t="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><WebUrlFromPageUrl xmlns='http://schemas.microsoft.com/sharepoint/soap/' ><pageUrl>"+window.location.href.replace(/&/g,"&")+"</pageUrl></WebUrlFromPageUrl></soap:Body></soap:Envelope>",r=window.location.protocol+"//"+window.location.host+"/_vti_bin/Webs.asmx";jQuery.ajax({type:"POST",cache:!1,async:!0,url:r,data:t,contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(t){var r=t.getElementsByTagName("WebUrlFromPageUrlResult");r.length&&(e.url=r[0].firstChild.nodeValue.toLowerCase(),jQuery("body").data("sp-currenturl",e.url)),e.needQueue=!1}})}else this.url=this.url||jQuery("body").data("sp-currenturl")||window.location.protocol+"//"+window.location.host+L_Menu_BaseUrl;return this},_addInQueue:function(e){return this.listQueue.push(e),1===this.listQueue.length&&this._testQueue(),this},_testQueue:function(){if(this.needQueue){var e=this;setTimeout(function(){e._testQueue.call(e)},25)}else{if(this.listQueue.length>0){var t=this.listQueue.shift();t.callee.apply(this,Array.prototype.slice.call(t))}if(this.needQueue=this.listQueue.length>0,this.needQueue){var e=this;setTimeout(function(){e._testQueue.call(e)},25)}}},parse:function(e,t){var r=e.replace(/(\s+)?(=|~=|<=|>=|<>|<|>| LIKE | like )(\s+)?/g,"$2").replace(/""|''/g,"Null").replace(/==/g,"="),s=[];t=t===!1?!1:!0;for(var i=e.length,o="",n="",a=!1,l="",u={open:0},c=!1,h=0;h<r.length;h++){var p=r.charAt(h);switch(p){case"(":for(var f=h,d=!1;"("==r.charAt(h)&&i>h;)h++,u.open++;for(;u.open>0&&i>h;){h++;var m=r.charAt(h);"\\"==m?a=!0:a||"'"!=m?a||")"!=m||d?a=!1:u.open--:d=!d}var g=s.length-1;g>=0?(""!=o&&(s[0]="<"+o+">"+s[0]),s[0]+=this.parse(r.substring(f+1,h)),""!=o&&(s[0]+="</"+o+">"),o=""):s[0]=this.parse(r.substring(f+1,h));break;case">":case"<":h++,"="==r.charAt(h)?(s.push("<"+(">"==p?"G":"L")+"eq>"),n="</"+(">"==p?"G":"L")+"eq>"):"<"==p&&">"==r.charAt(h)?(s.push("<Neq>"),n="</Neq>"):(h--,s.push("<"+(">"==p?"G":"L")+"t>"),n="</"+(">"==p?"G":"L")+"t>");break;case"~":"="==r.charAt(h+1)&&(c=!0);break;case"=":s.push("<Eq>"),n="</Eq>";break;case" ":" AND "==r.substring(h,h+5).toUpperCase()?(o="And",h+=4):" OR "==r.substring(h,h+4).toUpperCase()?(o="Or",h+=3):" LIKE "==r.slice(h,h+6).toUpperCase()?(h+=5,s.push("<Contains>"),n="</Contains>"):l+=p;break;case'"':case"'":for(var v=p,y="",w="";(p=r.charAt(++h))!=v&&i>h;)"\\"==p&&(p=r.charAt(++h)),y+=p;g=s.length-1,s[g]+='<FieldRef Name="'+l+'" '+("[Me]"==y?'LookupId="True" ':"")+"/>",l="";var b="Text";/\d{4}-\d\d?-\d\d?((T| )\d{2}:\d{2}:\d{2})?/.test(y)&&(b="DateTime",/\d{4}-\d\d?-\d\d?((T| )\d{2}:\d{2}:\d{2})/.test(y)&&(w=' IncludeTimeValue="TRUE"')),t&&(y=this._cleanString(y)),"[Me]"===y?(y='<UserID Type="Integer" />',b="Integer"):"[Today"==y.slice(0,6)&&(b="DateTime",y='<Today OffsetDays="'+1*y.slice(6,-1)+'" />'),s[g]+='<Value Type="'+b+'"'+w+">"+y+"</Value>",s[g]+=n,n="",g>0&&(""!=o&&(s[0]="<"+o+">"+s[0]),s[0]+=s[g],""!=o&&(s[0]+="</"+o+">"),delete s[g],o="");break;case"0":case"1":case"2":case"3":case"4":case"5":case"6":case"7":case"8":case"9":if(""!=n){for(var x=p;!isNaN(p=r.charAt(++h))&&i>h;)x+=""+p;g=s.length-1,s[g]+='<FieldRef Name="'+l+'"'+(c?' LookupId="True"':"")+" />",l="",s[g]+='<Value Type="'+(c?"Integer":"Number")+'">'+x.replace(/ $/,"")+"</Value>",s[g]+=n,n="",g>0&&(""!=o&&(s[0]="<"+o+">"+s[0]),s[0]+=s[g],""!=o&&(s[0]+="</"+o+">"),delete s[g],o=""),h-=2;break}default:""==n?l+=p:"n"==p.toLowerCase()&&"null"==r.substring(h,h+4).toLowerCase()&&(g=s.length-1,"</Neq>"==n?(s[g]="<IsNotNull>",n="</IsNotNull>"):"</Eq>"==n&&(s[g]="<IsNull>",n="</IsNull>"),h+=3,s[g]+='<FieldRef Name="'+l+'" />',l="",s[g]+=n,n="",g>0&&(""!=o&&(s[0]="<"+o+">"+s[0]),s[0]+=s[g],""!=o&&(s[0]+="</"+o+">"),delete s[g],o=""))}}return s.join("")},_parseOn:function(e){for(var t=[],r=e.replace(/(\s+)?(=)(\s+)?/g,"$2").replace(/==/g,"=").split(" AND "),s=0;s<r.length;s++){var i=r[s].match(/'([^']+)'\.([a-zA-Z0-9_]+)='([^']+)'\.([a-zA-Z0-9_]+)/);if(i&&5==i.length){var o={};o[i[1]]=i[2],o[i[3]]=i[4],t.push(o)}}return t},_cleanString:function(e){return e.replace(/&(?!amp;|lt;|gt;)/g,"&").replace(/</g,"<").replace(/>/g,">")},cleanResult:function(e,t){return null===e||"undefined"==typeof e?"":(t=t||";","string"==typeof e?e.replace(/;#[0-9]+;#/g,t).replace(/^[0-9]+;#/,"").replace(/^;#|;#$/g,"").replace(/;#/g,t).replace(/string;#/,""):e)},get:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'get': you have to define the list ID/Name";if(1===arguments.length&&"function"==typeof e)return this.get({},e);if(e=e||{},void 0==this.url)throw"Error 'get': not able to find the URL!";if(e.fields=e.fields||"",e.where=e.where||"",e.whereFct=e.whereFct||function(e){return e},e.orderby=e.orderby||"",e.useIndexForOrderBy=e.useIndexForOrderBy===!0?!0:!1,e.groupby=e.groupby||"",e.rowlimit=e.rowlimit||0,e.whereEscapeChar=e.whereEscapeChar===!1?!1:!0,e.paging=e.paging===!0?!0:!1,e.page=e.paging===!1||isNaN(e.page)?5e3:e.page,e.paging&&0===e.rowlimit&&(e.rowlimit=5e3),e.expandUserField=e.expandUserField===!0||"True"===e.expandUserField?"True":"False",e.dateInUTC=e.dateInUTC===!0?"True":"False",e.folderOptions=e.folderOptions||null,e.view=e.view||"",e.calendar=e.calendar===!0?!0:!1,e.calendar===!0&&(e.calendarOptions=e.calendarOptions||{},e.calendarOptions.referenceDate=e.calendarOptions.referenceDate||new Date,"string"!=typeof e.calendarOptions.referenceDate&&(e.calendarOptions.referenceDate=this.toSPDate(e.calendarOptions.referenceDate)),e.calendarOptions.splitRecurrence=e.calendarOptions.splitRecurrence===!1?"FALSE":"TRUE",e.calendarOptions.range=e.calendarOptions.range||"Month"),e.results=e.results||[],e.ListItemCollectionPositionNext=e.ListItemCollectionPositionNext||"","object"==typeof e.where?(e.where=e.where.slice(0),void 0==e.originalWhere&&(e.originalWhere=e.where.slice(0)),e.nextWhere=e.where.slice(1),e.where=e.where.shift()):(e.originalWhere=e.where,e.nextWhere=[]),e.progress=e.progress||function(){},""!==e.view){var r=this;return r.view(e.view,function(s,i){e.view=i,e.fields;var o=e.whereCAML?e.where:r.parse(e.where),n=s.whereCAML.match(/^<And>(<DateRangesOverlap>.*<\/DateRangesOverlap>)(.*)<\/And>$/);return n&&3===n.length&&(s.whereCAML="<And>"+n[2]+n[1]+"</And>"),o+=s.whereCAML,""!==e.where&&""!==s.whereCAML&&(o="<And>"+o+"</And>"),e.where=o,e.fields+=(""===e.fields?"":",")+s.fields.join(","),e.orderby+=(""===e.orderby?"":",")+s.orderby,e.whereCAML=!0,e.useOWS=!0,e.calendarViaView=e.calendar,e.calendar=!1,delete e.view,r.get.call(r,e,t)}),this}var s=!0,i="";if(""==e.fields||e.fields==[])i="";else{"string"==typeof e.fields&&(e.fields=e.fields.replace(/^\s+/,"").replace(/\s+$/,"").replace(/( )?,( )?/g,",").split(","));for(var o=0;o<e.fields.length;o++)i+='<FieldRef Name="'+e.fields[o]+'" />'}var n="";if(""!=e.orderby){var a=e.orderby.split(",");for(o=0;o<a.length;o++){var l="ASC",u=jQuery.trim(a[o]).split(" ");u.length>0&&(2==u.length&&(l=u[1].toUpperCase()),n+=s?'<FieldRef Name="'+u[0]+'" Ascending="'+("ASC"==l)+'" />':'<OrderField Name="'+u[0]+'" Direction="'+l+'" />')}}e.calendar!==!0&&e.calendarViaView!==!0||""!==n||(n='<FieldRef Name="EventDate" Ascending="ASC" />');var c="";if(""!=e.groupby){var h=e.groupby.split(",");for(o=0;o<h.length;o++)c+='<FieldRef Name="'+h[o]+'" />'}if(e.calendar===!0||e.calendarViaView===!0){var p=["Title","EventDate","EndDate","Duration","fAllDayEvent","fRecurrence","RecurrenceData","ID"];for(o=0;o<p.length;o++)i+='<FieldRef Name="'+p[o]+'" />'}var f="",d=[];if(void 0===e.queryOptions)if(e._queryOptions="<DateInUtc>"+e.dateInUTC+'</DateInUtc><Paging ListItemCollectionPositionNext="'+e.ListItemCollectionPositionNext+'"></Paging><IncludeAttachmentUrls>True</IncludeAttachmentUrls>'+(""===i?"":"<IncludeMandatoryColumns>False</IncludeMandatoryColumns>")+"<ExpandUserField>"+e.expandUserField+"</ExpandUserField>",e.folderOptions){var m;switch(e.folderOptions.show){case"FilesAndFolders_Recursive":m="RecursiveAll";break;case"FilesOnly_InFolder":m="FilesOnly";break;case"FilesAndFolders_InFolder":m="";break;case"FilesOnly_Recursive":default:m="Recursive"}e._queryOptions+='<ViewAttributes Scope="'+m+'"></ViewAttributes>',e.folderOptions.path&&(e._queryOptions+="<Folder>"+this.url+"/"+this.listID+"/"+e.folderOptions.path+"</Folder>")}else e._queryOptions+='<ViewAttributes Scope="Recursive"></ViewAttributes>';else e._queryOptions=e.queryOptions;e.calendarOptions&&(e._queryOptions+="<CalendarDate>"+e.calendarOptions.referenceDate+"</CalendarDate><RecurrencePatternXMLVersion>v3</RecurrencePatternXMLVersion><ExpandRecurrence>"+e.calendarOptions.splitRecurrence+"</ExpandRecurrence>");var g="";if(""!==e.where&&(g=e.whereCAML?e.where:this.parse(e.where)),e.calendar===!0){var v="<DateRangesOverlap><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /><FieldRef Name='RecurrenceID' /><Value Type='DateTime'><"+e.calendarOptions.range+" /></Value></DateRangesOverlap>";g=""!==g?"<And>"+g+v+"</And>":v}g=e.whereFct(g);var r=this;if(s){f='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>'+this.listID+"</listName><viewName>"+e.view+"</viewName><query><Query>"+(""!=g?"<Where>"+g+"</Where>":"")+(""!=c?"<GroupBy>"+c+"</GroupBy>":"")+(""!=n?"<OrderBy"+(e.useIndexForOrderBy?" UseIndexForOrderBy='TRUE' Override='TRUE'":"")+">"+n+"</OrderBy>":"")+"</Query></query><viewFields><ViewFields Properties='True'>"+i+"</ViewFields></viewFields><rowLimit>"+e.rowlimit+"</rowLimit><queryOptions><QueryOptions>"+e._queryOptions+"</QueryOptions></queryOptions></GetListItems></soap:Body></soap:Envelope>";var y=this.url+"/_vti_bin/Lists.asmx";jQuery.ajax({type:"POST",cache:!1,async:!0,url:y,data:f,contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(s){var i=s.getElementsByTagName("z:row");if(0==i.length&&(i=s.getElementsByTagName("row")),d=fastMap(i,function(e){return myElem(e)}),e.joinData){var o=e.joinData.noindex,n=[],a="",l={length:0};o.length||alert("$SP.get() -- Error 'get': you must define the ON clause with JOIN is used.");for(var u=0,c=d.length;c>u;u++){for(var h="",p=0;p<o.length;p++)h+=d[u].getAttribute(o[p][r.listID]);if(e.joinData[h]){a!==h&&(l[e.joinIndex[h]]=!0,l.length++,a=h);for(var p=0,f=e.joinData[h].length;f>p;p++){for(var m=[],g=d[u].getAttributes(),v=g.length;v--;)m[r.listID+"."+g[v].nodeName.slice(4)]=g[v].nodeValue;var y=e.joinData[h][p].getAttributes();for(var v in y)m[v]=e.joinData[h][p].getAttribute(v);n.push(new extendMyObject(m))}}e.innerjoin&&(e.join=e.innerjoin),e.outerjoin&&(e.join=e.outerjoin,e.join.outer=!0)}if(d=n,e.outer){var w=e.joinIndex.length;if(l.length<w)for(u=0;w>u;u++)if(l[u]!==!0){var b=e.joinIndex[u];if(void 0===b||void 0===e.joinData[b])continue;for(var p=0,f=e.joinData[b].length;f>p;p++){var m=[],y=e.joinData[b][p].getAttributes();for(var v in y)m[v]=e.joinData[b][p].getAttribute(v);n.push(new extendMyObject(m))}}}}if(e.outerjoin?(e.join=e.outerjoin,e.join.outer=!0):e.innerjoin&&(e.join=e.innerjoin),e.join){var x=[],T=[],o=r._parseOn(e.join.on);x.noindex=o;for(var u=0,c=d.length;c>u;u++){for(var h="",m=[],p=0;p<o.length;p++)h+=d[u].getAttribute(o[p][r.listID])||d[u].getAttribute(r.listID+"."+o[p][r.listID]);if(x[h]||(T[h]=T.length,T.push(h),x[h]=[]),e.joinData)x[h].push(d[u]);else{for(var N=d[u].getAttributes(),p=N.length;p--;)m[r.listID+"."+N[p].nodeName.slice(4)]=N[p].nodeValue;x[h].push(new extendMyObject(m))}}delete e.joinData;var E=$SP().list(e.join.list,e.join.url||r.url);e.join.joinData=x,e.join.joinIndex=T,E.get(e.join,t)}else{if(e.results.length>0)for(var u=0,c=d.length;c>u;u++)e.results.push(d[u]);if("string"!=typeof e.originalWhere&&e.progress(e.originalWhere.length-e.nextWhere.length,e.originalWhere.length),e.paging&&--e.page>0){var _=s.getElementsByTagName("rs:data")[0];0==_.length&&(_=s.getElementsByTagName("data")),0===e.results.length&&(e.results=d),e.progress(e.results.length);var I=_.getAttribute("ListItemCollectionPositionNext");I?(e.ListItemCollectionPositionNext=r._cleanString(_.getAttribute("ListItemCollectionPositionNext")),r.get(e,t)):"function"==typeof t&&t.call(r,e.results)}else e.nextWhere.length>0?(0===e.results.length&&(e.results=d),e.where=e.nextWhere.slice(0),r.get(e,t)):"function"==typeof t&&(e.where=e.originalWhere,t.call(r,e.results.length>0?e.results:d))}},error:function(e,s,i){var o=e.responseXML,n=o.getElementsByTagName("errorstring");n&&n[0]?t.call(r,[],"Error: "+n[0].firstChild.nodeValue):t.call(r,[],s+": "+i)}})}return this},createFile:function(e){if(e=e||{},void 0==e.content)throw"Error 'createFile': not able to find the file content.";if(void 0==e.destination)throw"Error 'createFile': not able to find the file destination path.";if(e.url=e.url||this.url,!e.url)return this._getURL(),this._addInQueue(arguments);if(void 0==e.url)throw"Error 'createFile': not able to find the URL!";e.after=e.after||function(){},e.encoded=void 0==e.encoded?!1:e.encoded;var t=this,r='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><CopyIntoItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><SourceUrl>http://null</SourceUrl><DestinationUrls><string>'+e.destination+"</string></DestinationUrls><Fields><FieldInformation Type='File' /></Fields><Stream>"+(e.encoded?e.content:encode_b64(e.content))+"</Stream></CopyIntoItems></soap:Body></soap:Envelope>";return jQuery.ajax({url:e.url+"/_vti_bin/copy.asmx",type:"POST",dataType:"xml",data:r,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems")},contentType:'text/xml; charset="utf-8"',success:function(r){var s=r.getElementsByTagName("CopyResult");if(s&&s[0]&&"Success"!=s[0].getAttribute("ErrorCode"))throw"Error 'createFile': "+s[0].getAttribute("ErrorCode")+" - "+s[0].getAttribute("ErrorMessage");"function"==typeof e.after&&e.after.call(t)}}),this},createFolder:function(e){if(e=e||{},void 0==e.path)throw"Error 'createFolder': please provide the 'path'.";if(void 0==e.library)throw"Error 'createFolder': please provide the library name.";if(e.url=e.url||this.url,!e.url)return this._getURL(),this._addInQueue(arguments);if(void 0==e.url)throw"Error 'createFolder': not able to find the URL!";e.after=e.after||function(){};for(var t=e.path.split("/"),r=[],s="",i=0;i<t.length;i++)s+=(i>0?"/":"")+t[i],r.push({FSObjType:1,BaseName:s});return this.list(e.library,e.url).add(r,{after:e.after}),this},checkin:function(e){if(e=e||{},void 0==e.destination)throw"Error 'checkin': not able to find the file destination path.";if(e.url=e.url||this.url,!e.url)return this._getURL(),this._addInQueue(arguments);if(void 0==this.url)throw"Error 'checkin': not able to find the URL!";e.url=this.url,e.comments=e.comments||"",e.success=e.success||function(){},e.error=e.error||function(){},e.after=e.after||function(){};var t=this,r='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><CheckInFile xmlns="http://schemas.microsoft.com/sharepoint/soap/"><pageUrl>'+e.destination+"</pageUrl><comment>"+e.comments+"</comment><CheckinType>1</CheckinType></CheckInFile></soap:Body></soap:Envelope>";jQuery.ajax({url:e.url+"/_vti_bin/Lists.asmx",type:"POST",dataType:"xml",data:r,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/CheckInFile")},contentType:"text/xml; charset=utf-8",success:function(r){var s=r.getElementsByTagName("CheckInFileResult");s&&s[0]&&"true"!=s[0].firstChild.nodeValue?e.error.call(t):e.success.call(t),e.after.call(t)}})},getAttachment:function(e,t,r){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'getAttachment': you have to define the list ID/Name";if(1===arguments.length&&"function"==typeof e)throw"Error 'getAttachment': you have to define the item ID";if(void 0==this.url)throw"Error 'getAttachment': not able to find the URL!";"object"!=typeof e&&(e=e.split(",")),r=r||[];var s='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetAttachmentCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/"> <listName>'+this.listID+"</listName> <listItemID>"+e.shift()+"</listItemID> </GetAttachmentCollection> </soap:Body></soap:Envelope>",i=this,o=this.url+"/_vti_bin/lists.asmx",n=[];return jQuery.ajax({type:"POST",cache:!1,async:!0,url:o,data:s,contentType:"text/xml; charset=utf-8",beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetAttachmentCollection")},dataType:"xml",success:function(s){for(var o=s.getElementsByTagName("Attachment"),a=0;a<o.length;a++)n.push(o[a].firstChild.nodeValue);0===n.length?n="":1===n.length&&(n=n[0]),r.push(n),0===e.length?"function"==typeof t&&t.call(i,r):i.getAttachment(e,t,r)}}),this},info:function(e){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'info': you have to define the list ID";if(void 0==this.url)throw"Error 'info': not able to find the URL!";var t='<?xml version="1.0" encoding="utf-8"?>';t+='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',t+=" <soap:Body>",t+=' <GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/">',t+=" <listName>"+this.listID+"</listName>",t+=" </GetList>",t+=" </soap:Body>",t+="</soap:Envelope>";var r=this,s=this.url+"/_vti_bin/lists.asmx",i=[];return jQuery.ajax({type:"POST",cache:!1,async:!0,url:s,data:t,contentType:"text/xml; charset=utf-8",beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetList")},dataType:"xml",success:function(t){for(var s,o,n,a,l=t.getElementsByTagName("Field"),u=0,c=0;c<l.length;c++)if(l[c].getAttribute("ID")){i[u]=[],s=i[u],o=l[c].attributes;for(var h=o.length;h--;){if(n=o[h].nodeName,attrValue=o[h].nodeValue,"Type"===n)switch(attrValue){case"Choice":case"MultiChoice":s.FillInChoice=l[c].getAttribute("FillInChoice");for(var p=l[c].getElementsByTagName("CHOICE"),f=[],d=0;d<p.length;d++)f.push(p[d].firstChild.nodeValue);s.Choices=f;break;case"Lookup":case"LookupMulti":s.Choices={list:l[c].getAttribute("List"),field:l[c].getAttribute("ShowField")};break;default:s.Choices=[]}s[n]=attrValue}if(a=l[c].getElementsByTagName("Default").length,a>0){nodeDefault=l[c].getElementsByTagName("Default"),i[u].DefaultValue=[];for(var m=0;a>m;m++)nodeDefault[m].firstChild&&i[u].DefaultValue.push(nodeDefault[m].firstChild.nodeValue);1===a&&(i[u].DefaultValue=i[u].DefaultValue[0])}else i[u].DefaultValue=null;u++}"function"==typeof e&&e.call(r,i)}}),this},view:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'view': you have to define the list ID/Name";if(1===arguments.length&&"function"==typeof e)return this.view("",e);if(list=this.listID,void 0==this.url)throw"Error 'view': not able to find the URL!";e=e||"";var r=arguments[2]||e;r=r.toLowerCase();var s=jQuery("body").data("sp-view");if(void 0!=s){for(var i=s.length;i--;)if(s[i].url===this.url&&(s[i].viewID===e||s[i].viewName===r))return t.call(this,s[i].data,e),this}else s=[];if("{"!==e.charAt(0))return this.views(function(r){for(var s=!1,i=r.length;i--;)if(r[i].Name===e){this.view(r[i].ID,t,e),s=!0;break}if(!s)throw"Error 'view': not able to find the view called '"+e+"' at "+this.url}),this;var o='<?xml version="1.0" encoding="utf-8"?>';o+='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',o+=" <soap:Body>",o+=' <GetView xmlns="http://schemas.microsoft.com/sharepoint/soap/">',o+=" <listName>"+this.listID+"</listName>",o+=" <viewName>"+e+"</viewName>",o+=" </GetView>",o+=" </soap:Body>",o+="</soap:Envelope>";var n=this.url+"/_vti_bin/Views.asmx",a=["fields","orderby","whereCAML"],l=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:n,data:o,contentType:"text/xml; charset=utf-8",beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetView")},dataType:"xml",success:function(i){a.fields=[];for(var o=i.getElementsByTagName("ViewFields")[0].getElementsByTagName("FieldRef"),n=0;n<o.length;n++)a.fields.push(o[n].getAttribute("Name"));if(a.orderby="",o=i.getElementsByTagName("OrderBy"),o.length){var u=[];o=o[0].getElementsByTagName("FieldRef");for(var n=0;n<o.length;n++)u.push(o[n].getAttribute("Name")+" "+(void 0==o[n].getAttribute("Ascending")?"ASC":"DESC"));a.orderby=u.join(",")}a.whereCAML="";var c=i.getElementsByTagName("Where");c.length&&(c=c[0].xml||(new XMLSerializer).serializeToString(c[0]),c=c.match(/<Where [^>]+>(.*)<\/Where>/),2==c.length&&(a.whereCAML=c[1])),s.push({url:l.url,data:a,viewID:e,viewName:r}),jQuery("body").data("sp-view",s),"function"==typeof t&&t.call(l,a,e)}}),this},views:function(e,t){if("function"==typeof e)return this.views({},e);if(e.cache=e.cache===!1?!1:!0,this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'views': you have to define the list ID";if(void 0==this.url)throw"Error 'views': not able to find the URL!";t=t||function(){};var r=jQuery("body").data("sp-views");if(void 0!=r&&e.cache){for(var s=r.length;s--;)if(r[s].url==this.url&&r[s].listID===this.listID)return t.call(this,r[s].data),this}else r=[];var i='<?xml version="1.0" encoding="utf-8"?>';i+='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',i+=" <soap:Body>",i+=' <GetViewCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/">',i+=" <listName>"+this.listID+"</listName>",i+=" </GetViewCollection>",i+=" </soap:Body>",i+="</soap:Envelope>";var o=this.url+"/_vti_bin/Views.asmx",n=[],a=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:o,data:i,contentType:"text/xml; charset=utf-8",beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetViewCollection")},dataType:"xml",success:function(s){for(var i=s.getElementsByTagName("View"),o=0;o<i.length;o++)n[o]=[],n[o].ID=i[o].getAttribute("Name"),n[o].Name=i[o].getAttribute("DisplayName"),n[o].Url=i[o].getAttribute("Url"),n[o].Node=i[o];e.cache===!0&&(r.push({url:a.url,listID:this.listID,data:n}),jQuery("body").data("sp-views",r)),t.call(a,n)}}),this},lists:function(e,t){if(1===arguments.length&&"function"==typeof e)return this.lists({},e);if(e=e||{},e.url=e.url||this.url,!e.url)return this._getURL(),this._addInQueue(arguments);if(this.url=e.url,void 0==this.url)throw"Error 'lists': not able to find the URL!";var r='<?xml version="1.0" encoding="utf-8"?>';r+='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">',r+=" <soap:Body>",r+=' <GetListCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/">',r+=" </GetListCollection>",r+=" </soap:Body>",r+="</soap:Envelope>";var s=jQuery("body").data("sp-lists");if(void 0!=s){for(var i=s.length;i--;)if(s[i].url==this.url)return"function"==typeof t?t(s[i].data):(this.data=s[i].data,this.length=this.data.length),this}else s=[];var o=this.url+"/_vti_bin/lists.asmx",n=[],a=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:o,data:r,contentType:"text/xml; charset=utf-8",beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetListCollection")},dataType:"xml",success:function(e){for(var r=e.getElementsByTagName("List"),i=0;i<r.length;i++)n[i]=[],n[i].ID=r[i].getAttribute("ID"),n[i].Name=r[i].getAttribute("Title"),n[i].Url=r[i].getAttribute("DefaultViewUrl"),n[i].Description=r[i].getAttribute("Description");s.push({url:a.url,data:n}),jQuery("body").data("sp-lists",s),"function"==typeof t&&t.call(a,n)}}),this},add:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(0===arguments.length||1===arguments.length&&"object"!=typeof e)throw"Error 'add': you need to define the list of items";if(void 0===this.listID)throw"Error 'add': you need to use list() to define the list name.";if(t=t||{},void 0==this.url)throw"Error 'add': not able to find the URL!";t.success=t.success||function(){},t.error=t.error||function(){},t.after=t.after||function(){},t.escapeChar=void 0==t.escapeChar?!0:t.escapeChar,t.progress=t.progress||function(){},"object"==typeof e&&void 0==e.length&&(e=[e]);var r=e.length;if(t.progressVar=t.progressVar||{current:0,max:r,passed:[],failed:[],eventID:"spAdd"+(""+Math.random()).slice(2)},r>15){var s=e.slice(0),i=s.splice(0,15),o=this;return jQuery(document).on(t.progressVar.eventID,function(e){jQuery(document).off(t.progressVar.eventID),o.add(s,e.setup)}),this.add(i,t),this}if(0==r)return t.progress(1,1),t.error([]),t.success([]),t.after(),this;t.progressVar.current+=r;for(var n='<Batch OnError="Continue" ListVersion="1" ViewName="">',o=this,a=0;a<e.length;a++)n+='<Method ID="'+(a+1)+'" Cmd="New">',n+="<Field Name='ID'>New</Field>",jQuery.each(e[a],function(e,r){"object"==typeof r&&void 0!=r.items&&(r=";#"+r.join(";#")+";#"),t.escapeChar&&"string"==typeof r&&(r=o._cleanString(r)),n+="<Field Name='"+e+"'>"+r+"</Field>"}),n+="</Method>";n+="</Batch>";var l='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>'+this.listID+"</listName><updates>"+n+"</updates></UpdateListItems></soap:Body></soap:Envelope>",u=this.url+"/_vti_bin/lists.asmx",o=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:u,data:l,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(r){for(var s=r.getElementsByTagName("Result"),i=s.length,n=t.progressVar.passed,a=t.progressVar.failed,l=0;i>l;l++)if("0x00000000"==s[l].getElementsByTagName("ErrorCode")[0].firstChild.nodeValue){var u=s[l].getElementsByTagName("z:row");0==u.length&&(u=s[l].getElementsByTagName("row")),e[l]&&(e[l].ID=u[0].getAttribute("ows_ID"),n.push(e[l]))}else e[l]&&(e[l].errorMessage=s[l].getElementsByTagName("ErrorText")[0].firstChild.nodeValue,a.push(e[l]));t.progress(t.progressVar.current,t.progressVar.max),t.progressVar.current<t.progressVar.max?jQuery(document).trigger({type:t.progressVar.eventID,setup:t}):(a.length>0&&t.error.call(o,a),n.length>0&&t.success.call(o,n),t.after.call(o))}}),this},update:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(void 0===this.listID)throw"Error 'update': you need to use list() to define the list name.";if(t=t||{},void 0==this.url)throw"Error 'update': not able to find the URL!";t.where=t.where||"",t.success=t.success||function(){},t.error=t.error||function(){},t.after=t.after||function(){},t.escapeChar=void 0==t.escapeChar?!0:t.escapeChar,t.progress=t.progress||function(){},"object"==typeof e&&void 0==e.length&&(e=[e]);var r=e.length;if(1==r&&t.where){delete e[0].ID;var s=this;return this.get({fields:"ID",where:t.where},function(r){for(var i=function(e){var t={};for(var r in e)t[r]=e[r];return t},o=[],n=r.length;n--;){var a=i(e[0]);a.ID=r[n].getAttribute("ID"),o.push(a)}delete t.where,s.update(o,t)}),this}if(t.progressVar=t.progressVar||{current:0,max:r,passed:[],failed:[],eventID:"spUpdate"+(""+Math.random()).slice(2)},r>15){var i=e.slice(0),o=i.splice(0,15),s=this;return jQuery(document).on(t.progressVar.eventID,function(e){jQuery(document).off(t.progressVar.eventID),s.update(i,e.setup)}),this.update(o,t),this}if(0==r)return t.progress(1,1),t.error([]),t.success([]),t.after(),this;t.progressVar.current+=r;for(var n='<Batch OnError="Continue" ListVersion="1" ViewName="">',s=this,a=0;r>a;a++){if(n+='<Method ID="'+(a+1)+'" Cmd="Update">',void 0==e[a].ID)throw"Error 'update': you have to provide the item ID called 'ID'";jQuery.each(e[a],function(e,r){"object"==typeof r&&void 0!=r.length&&(r=";#"+r.join(";#")+";#"),t.escapeChar&&"string"==typeof r&&(r=s._cleanString(r)),n+="<Field Name='"+e+"'>"+r+"</Field>"}),n+="</Method>"}n+="</Batch>";var l='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>'+this.listID+"</listName><updates>"+n+"</updates></UpdateListItems></soap:Body></soap:Envelope>",u=this.url+"/_vti_bin/lists.asmx",s=this;
return jQuery.ajax({type:"POST",cache:!1,async:!0,url:u,data:l,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(r){for(var i=r.getElementsByTagName("Result"),o=i.length,n=t.progressVar.passed,a=t.progressVar.failed,l=0;o>l;l++)"0x00000000"==i[l].getElementsByTagName("ErrorCode")[0].firstChild.nodeValue&&e[l]?n.push(e[l]):e[l]&&(e[l].errorMessage=i[l].getElementsByTagName("ErrorText")[0].firstChild.nodeValue,a.push(e[l]));t.progress(t.progressVar.current,t.progressVar.max),t.progressVar.current<t.progressVar.max?jQuery(document).trigger({type:t.progressVar.eventID,setup:t}):(a.length>0&&t.error.call(s,a),n.length>0&&t.success.call(s,n),t.after.call(s))}}),this},history:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(void 0===this.listID)throw"Error 'history': you need to use list() to define the list name.";if(2!==arguments.length)throw"Error 'history': you need to provide two parameters.";if("object"!=typeof e)throw"Error 'history': the first parameter must be an object.";if(void 0===e.ID||void 0===e.Name)throw"Error 'history': the first parameter must be an object with ID and Name.";if("function"!=typeof t)throw"Error 'history': the second parameter must be a function.";var r='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetVersionCollection xmlns="http://schemas.microsoft.com/sharepoint/soap/"><strlistID>'+this.listID+"</strlistID><strlistItemID>"+e.ID+"</strlistItemID><strFieldName>"+e.Name+"</strFieldName></GetVersionCollection></soap:Body></soap:Envelope>",s=this.url+"/_vti_bin/lists.asmx",i=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:s,data:r,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/GetVersionCollection")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(e){t.call(i,e.getElementsByTagName("Version"))}}),this},moderate:function(e,t){if(this.needQueue)return this._addInQueue(arguments);if(0===arguments.length||1===arguments.length&&"object"==typeof e&&void 0===e.length)throw"Error 'moderate': you need to define the list of items";if(void 0===this.listID)throw"Error 'moderate': you need to use list() to define the list name.";if(t=t||{},void 0==this.url)throw"Error 'moderate': not able to find the URL!";t.async=void 0==t.async?!0:t.async,t.success=t.success||function(){},t.error=t.error||function(){},t.after=t.after||function(){},t.progress=t.progress||function(){},"object"==typeof e&&void 0==e.length&&(e=[e]);var r=e.length;if(t.progressVar=t.progressVar||{current:0,max:r,passed:[],failed:[],eventID:"spModerate"+(""+Math.random()).slice(2)},r>15){var s=e.slice(0),i=s.splice(0,15),o=this;return jQuery(document).on(t.progressVar.eventID,function(e){jQuery(document).off(t.progressVar.eventID),o.moderate(s,e.setup)}),this.moderate(i,t),this}if(0==r)return t.progress(1,1),t.success([]),t.error([]),t.after(),this;t.progressVar.current+=r;for(var n='<Batch OnError="Continue" ListVersion="1" ViewName="">',a=0;r>a;a++){if(n+='<Method ID="'+(a+1)+'" Cmd="Moderate">',void 0==e[a].ID)throw"Error 'moderate': you have to provide the item ID called 'ID'";if(void 0==e[a].ApprovalStatus)throw"Error 'moderate': you have to provide the approval status 'ApprovalStatus' (Approved, Rejected, Pending, Draft or Scheduled)";jQuery.each(e[a],function(e,t){if("ApprovalStatus"==e)switch(e="_ModerationStatus",t.toLowerCase()){case"approve":case"approved":t=0;break;case"reject":case"deny":case"denied":case"rejected":t=1;break;case"pending":t=2;break;case"draft":t=3;break;case"scheduled":t=4;break;default:t=2}n+="<Field Name='"+e+"'>"+t+"</Field>"}),n+="</Method>"}n+="</Batch>";var l='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>'+this.listID+"</listName><updates>"+n+"</updates></UpdateListItems></soap:Body></soap:Envelope>",u=this.url+"/_vti_bin/lists.asmx",o=this;return jQuery.ajax({type:"POST",cache:!1,async:!0,url:u,data:l,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(r){for(var s,i=r.getElementsByTagName("Result"),n=i.length,a=t.progressVar.passed,l=t.progressVar.failed,u=0;n>u;u++){s=i[u].getElementsByTagName("z:row"),0==s.length&&(s=r.getElementsByTagName("row"));var c=myElem(s[0]);"0x00000000"==i[u].getElementsByTagName("ErrorCode")[0].firstChild.nodeValue?a.push(c):(e[u].errorMessage=i[u].getElementsByTagName("ErrorText")[0].firstChild.nodeValue,l.push(e[u]))}t.progress(t.progressVar.current,t.progressVar.max),t.progressVar.current<t.progressVar.max?jQuery(document).trigger({type:t.progressVar.eventID,setup:t}):(a.length>0&&t.success.call(o,a),l.length>0&&t.error.call(o,l),t.after.call(o))}}),this},remove:function(e,t){if(this.needQueue)return this._addInQueue(arguments);var r=this;if(!t&&e.where&&(t=e,e=[]),t=t||{},void 0==this.url)throw"Error 'remove': not able to find the URL!";t.error=t.error||function(){},t.success=t.success||function(){},t.after=t.after||function(){},t.progress=t.progress||function(){},"object"==typeof e&&void 0==e.length&&(e=[e]);var s=e.length;if(t.where)return 1==s&&delete e[0].ID,this.get({fields:"ID,FileRef",where:t.where},function(s){for(var i,o=function(e){var t={};for(var r in e)t[r]=e[r];return t},n=[],a=s.length;a--;){var l=o(e[0]);l.ID=s[a].getAttribute("ID"),i=s[a].getAttribute("FileRef"),i&&(l.FileRef=$SP().cleanResult(i)),n.push(l)}delete t.where,r.remove(n,t)}),r;if(0==s)return t.progress(1,1),t.error.call(r,[]),t.success.call(r,[]),t.after.call(r),r;if(t.progressVar=t.progressVar||{current:0,max:s,passed:[],failed:[],eventID:"spRemove"+(""+Math.random()).slice(2)},s>15){var i=e.slice(0),o=i.splice(0,15),r=this;return jQuery(document).on(t.progressVar.eventID,function(e){jQuery(document).off(t.progressVar.eventID),r.remove(i,e.setup)}),this.remove(o,t),this}t.progressVar.current+=s;for(var n='<Batch OnError="Continue" ListVersion="1" ViewName="">',a=0;a<e.length;a++){if(n+='<Method ID="'+(a+1)+'" Cmd="Delete">',void 0==e[a].ID)throw"Error 'delete': you have to provide the item ID called 'ID'";n+="<Field Name='ID'>"+e[a].ID+"</Field>",void 0!=e[a].FileRef&&(n+="<Field Name='FileRef'>"+e[a].FileRef+"</Field>"),n+="</Method>"}n+="</Batch>";var l='<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/"><listName>'+this.listID+"</listName><updates>"+n+"</updates></UpdateListItems></soap:Body></soap:Envelope>",r=this,u=this.url+"/_vti_bin/lists.asmx";return jQuery.ajax({type:"POST",cache:!1,async:!0,url:u,data:l,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/UpdateListItems")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(s){for(var i=s.getElementsByTagName("Result"),o=i.length,n=t.progressVar.passed,a=t.progressVar.failed,l=0;o>l;l++)"0x00000000"==i[l].getElementsByTagName("ErrorCode")[0].firstChild.nodeValue?n.push(e[l]):(e[l].errorMessage=i[l].getElementsByTagName("ErrorText")[0].firstChild.nodeValue,a.push(e[l]));t.progress(t.progressVar.current,t.progressVar.max),t.progressVar.current<t.progressVar.max?jQuery(document).trigger({type:t.progressVar.eventID,setup:t}):(a.length>0&&t.error.call(r,a),n.length>0&&t.success.call(r,n),t.after.call(r))}}),this},del:function(e,t){return this.remove(e,t)},usergroups:function(e,t,r){switch(arguments.length){case 1:if("object"==typeof e)return this.usergroups("",e,function(){});if("function"==typeof e)return this.usergroups("",{},e);break;case 2:if("string"==typeof e&&"function"==typeof t)return this.usergroups(e,{},t);if("object"==typeof e&&"function"==typeof t)return this.usergroups("",e,t)}if(t=t||{},t.cache=t.cache===!1?!1:!0,void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;if(r=r||function(){},!e)throw"Error 'usergroups': you have to set an username.";e=e.toLowerCase(),t.url=t.url.toLowerCase();var s=jQuery("body").data("sp-usergroups")||[];if(t.cache)for(var i=s.length;i--;)if(s[i].user.toLowerCase()==e&&s[i].url.toLowerCase()==t.url)return r.call(this,s[i].data),this;var o="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetGroupCollectionFromUser xmlns='http://schemas.microsoft.com/sharepoint/soap/directory/'><userLoginName>"+e+"</userLoginName></GetGroupCollectionFromUser></soap:Body></soap:Envelope>",n=this,a=t.url+"/_vti_bin/usergroup.asmx";return jQuery.ajax({type:"POST",cache:!1,url:a,data:o,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/directory/GetGroupCollectionFromUser")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(i){var o=[];i=i.getElementsByTagName("Group");for(var a=0,l=i.length;l>a;a++)o.push(i[a].getAttribute("Name"));s.push({user:e,url:t.url,data:o}),jQuery("body").data("sp-usergroups",s),r.call(n,o)},error:function(e){if(t.error===!1)r.call(n,[]);else{var s=e.responseXML.getElementsByTagName("errorstring");"object"==typeof console&&console.error("Error 'usergroups': "+s[0].firstChild.nodeValue)}}}),this},getWorkflowID:function(e){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'getWorkflowID': you have to define the list ID/Name";if(void 0==this.url)throw"Error 'getWorkflowID': not able to find the URL!";if(e=e||{},void 0==e.ID||void 0==e.workflowName||void 0==e.after)throw"Error 'getWorkflowID': all parameters are mandatory";return this.get({fields:"FieldRef",where:"ID = "+e.ID},function(t){if(0===t.length)throw"Error 'getWorkflowID': I'm not able to find the item ID "+e.ID;var r=this.cleanResult(t[0].getAttribute("FileRef")),s=r.substring(0,r.indexOf("/Lists")),t=this.url.substring(0,this.url.indexOf(s));r=t+r;var i='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetWorkflowDataForItem xmlns="http://schemas.microsoft.com/sharepoint/soap/workflow/"><item>'+r+"</item></GetWorkflowDataForItem></soap:Body></soap:Envelope>",o=this;jQuery.ajax({type:"POST",cache:!1,async:!0,url:this.url+"/_vti_bin/Workflow.asmx",data:i,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/workflow/GetWorkflowDataForItem")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(t){var s=t.getElementsByTagName("WorkflowTemplate");if(0===s.length)throw"Error 'getWorkflowID': No workflow found for this item";for(var i=s.length;i--;)if(s[i].getAttribute("Name")==e.workflowName)return e.after.call(o,{fileRef:r,workflowID:"{"+s[i].getElementsByTagName("WorkflowTemplateIdSet")[0].getAttribute("TemplateId")+"}"}),o;e.after.call(o,"Error 'getWorkflowID': impossible to find this workflow name!")},error:function(){throw"Error 'getWorkflowID': Something went wrong with the request over the Workflow Web Service..."}})}),this},startWorkflow:function(e){if(this.needQueue)return this._addInQueue(arguments);if(void 0==this.listID)throw"Error 'startWorkflow': you have to define the list ID/Name";if(void 0==this.url)throw"Error 'startWorkflow': not able to find the URL!";if(e=e||{},e.after=e.after||function(){},!e.workflowName&&!e.workflowID)throw"Error 'startWorkflow': Please provide the workflow name!";if(!e.ID)throw"Error 'startWorkflow': Please provide the item ID!";if(e.fileRef||e.workflowID){var t="<root />";if(e.parameters){var r;void 0==e.parameters.length&&(e.parameters=[e.parameters]),r=e.parameters.slice(0),t="<Data>";for(var s=0;s<r.length;s++)t+="<"+r[s].name+">"+r[s].value+"</"+r[s].name+">";t+="</Data>"}var i='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><StartWorkflow xmlns="http://schemas.microsoft.com/sharepoint/soap/workflow/"><item>'+e.fileRef+"</item><templateId>"+e.workflowID+"</templateId><workflowParameters>"+t+"</workflowParameters></StartWorkflow></soap:Body></soap:Envelope>",o=this,n=this.url+"/_vti_bin/Workflow.asmx";jQuery.ajax({type:"POST",cache:!1,async:!0,url:n,data:i,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/workflow/StartWorkflow")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(){e.after.call(o)},error:function(){e.after.call(o)}})}else this.getWorkflowID({ID:e.ID,workflowName:e.workflowName,after:function(t){e.fileRef=t.fileRef,e.workflowID=t.workflowID,this.startWorkflow(e)}});return this},distributionLists:function(e,t,r){switch(arguments.length){case 1:if("object"==typeof e)return this.distributionLists("",e,function(){});if("function"==typeof e)return this.distributionLists("",{},e);break;case 2:if("string"==typeof e&&"function"==typeof t)return this.distributionLists(e,{},t);if("object"==typeof e&&"function"==typeof t)return this.distributionLists("",e,t)}if(t=t||{},void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;if(r=r||function(){},!e)throw"Error 'distributionLists': you have to set an username.";e=e.toLowerCase(),t.url=t.url.toLowerCase(),t.cache=t.cache===!1?!1:!0;var s=jQuery("body").data("sp-distributionLists")||[];if(t.cache)for(var i=s.length;i--;)if(s[i].user===e&&s[i].url===t.url)return r.call(this,s[i].data),this;var o="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetCommonMemberships xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'><accountName>"+e+"</accountName></GetCommonMemberships></soap:Body></soap:Envelope>",n=this,a=t.url+"/_vti_bin/UserProfileService.asmx";return jQuery.ajax({type:"POST",cache:!1,url:a,data:o,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://microsoft.com/webservices/SharePointPortalServer/UserProfileService/GetUserMemberships")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(i){var o=[];i=i.getElementsByTagName("MembershipData");for(var a=0,l=i.length;l>a;a++)"DistributionList"===i[a].getElementsByTagName("Source")[0].firstChild.nodeValue&&o.push({SourceReference:i[a].getElementsByTagName("SourceReference")[0].firstChild.nodeValue,DisplayName:i[a].getElementsByTagName("DisplayName")[0].firstChild.nodeValue,MailNickname:i[a].getElementsByTagName("MailNickname")[0].firstChild.nodeValue,Url:i[a].getElementsByTagName("Url")[0].firstChild.nodeValue});s.push({user:e,url:t.url,data:o}),jQuery("body").data("sp-distributionLists",s),r.call(n,o)},error:function(){r.call(n,[])}}),this},groupMembers:function(e,t,r){switch(arguments.length){case 1:if("object"==typeof e)return this.groupMembers("",e,function(){});if("function"==typeof e)return this.groupMembers("",{},e);break;case 2:if("string"==typeof e&&"function"==typeof t)return this.groupMembers(e,{},t);if("object"==typeof e&&"function"==typeof t)return this.groupMembers("",e,t)}if(t=t||{},t.cache=void 0===t.cache?!0:t.cache,void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;if(r=r||function(){},!e)throw"Error 'groupMembers': you have to set an groupname.";e=e.toLowerCase(),t.url=t.url.toLowerCase();var s=[];if(t.cache){s=jQuery("body").data("sp-groupMembers")||[];for(var i=s.length;i--;)if(s[i].group===e&&s[i].url===t.url)return r.call(this,s[i].data),this}var o="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetUserCollectionFromGroup xmlns='http://schemas.microsoft.com/sharepoint/soap/directory/'><groupName>"+this._cleanString(e)+"</groupName></GetUserCollectionFromGroup></soap:Body></soap:Envelope>",n=this,a=t.url+"/_vti_bin/usergroup.asmx";return jQuery.ajax({type:"POST",cache:!1,url:a,data:o,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/directory/GetUserCollectionFromGroup")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(i){var o=[];i=i.getElementsByTagName("User");for(var a=0,l=i.length;l>a;a++)o.push({ID:i[a].getAttribute("ID"),Name:i[a].getAttribute("Name"),LoginName:i[a].getAttribute("LoginName"),Email:i[a].getAttribute("Email")});s.push({group:e,url:t.url,data:o}),jQuery("body").data("sp-groupMembers",s),r.call(n,o)},error:function(e){if(t.error===!1)r.call(n,[]);else{var s=e.responseXML.getElementsByTagName("errorstring");"object"==typeof console&&console.error("Error 'groupMembers': "+s[0].firstChild.nodeValue)}}}),this},isMember:function(e,t){if(e=e||{},e.cache=e.cache===!1?!1:!0,void 0==e.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);e.url=this.url}else this.url=e.url;if(t=t||function(){},!e.user)throw"Error 'isMember': you have to set an user.";if(!e.group)throw"Error 'isMember': you have to set a group.";return e.group=e.group.toLowerCase(),this.usergroups(e.user,{cache:e.cache,error:!1},function(r){for(var s=r.length;s--;)if(r[s].toLowerCase()===e.group)return t.call(this,!0),this;this.groupMembers(e.group,{cache:e.cache,error:!1},function(r){for(var s=[],i=r.length;i--;)s.push(r[i].Name.toLowerCase());this.distributionLists(e.user,{cache:e.cache},function(e){for(var r=e.length;r--;)if(s.indexOf(e[r].DisplayName.toLowerCase())>-1)return t.call(this,!0),this;return t.call(this,!1),this})})}),this},people:function(e,t,r){switch(arguments.length){case 1:if("object"==typeof e)return this.people("",e,function(){});if("function"==typeof e)return this.people("",{},e);e=void 0;break;case 2:if("string"==typeof e&&"function"==typeof t)return this.people(e,{},t);if("object"==typeof e&&"function"==typeof t)return this.people("",e,t)}if(t=t||{},void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;r=r||function(){},e=e||"";var s="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><GetUserProfileByName xmlns='http://microsoft.com/webservices/SharePointPortalServer/UserProfileService'><AccountName>"+e+"</AccountName></GetUserProfileByName></soap:Body></soap:Envelope>",i=this,o=t.url+"/_vti_bin/UserProfileService.asmx";return jQuery.ajax({type:"POST",cache:!1,url:o,data:s,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://microsoft.com/webservices/SharePointPortalServer/UserProfileService/GetUserProfileByName")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(e){var t=[];e=e.getElementsByTagName("PropertyData");for(var s=0,o=e.length;o>s;s++){var n=e[s].getElementsByTagName("Name")[0].firstChild.nodeValue,a=e[s].getElementsByTagName("Value");a=a&&a.length>=1&&a[0].firstChild?a[0].firstChild.nodeValue:"No Value",t.push(n),t[n]=a}r.call(i,t)},error:function(e){var t=e.responseXML.getElementsByTagName("faultstring");r.call(i,"Error 'people': "+t[0].firstChild.nodeValue)}}),this},getUserInfo:function(e,t,r){if("string"!=typeof e)throw"Error 'getUserInfo': the first argument must be the username";switch(arguments.length){case 2:if("function"==typeof t)return this.getUserInfo(e,{},t);if("object"==typeof t)return this.getUserInfo(e,t,function(){});break;case 3:if("object"!=typeof t&&"function"!=typeof r)throw"Error 'getUserInfo': incorrect arguments, please review the documentation"}if(t=t||{},void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;r=r||function(){};var s='<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><GetUserInfo xmlns="http://schemas.microsoft.com/sharepoint/soap/directory/"><userLoginName>'+e+"</userLoginName></GetUserInfo></soap:Body></soap:Envelope>",i=this,o=t.url+"/_vti_bin/usergroup.asmx";return jQuery.ajax({type:"POST",cache:!1,url:o,data:s,contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(e){e=e.getElementsByTagName("User"),0===e.length?r.call(i,"Error 'getUserInfo': nothing returned?!"):r.call(i,{ID:e[0].getAttribute("ID"),Sid:e[0].getAttribute("Sid"),Name:e[0].getAttribute("Name"),LoginName:e[0].getAttribute("LoginName"),Email:e[0].getAttribute("Email"),Notes:e[0].getAttribute("Notes"),IsSiteAdmin:e[0].getAttribute("IsSiteAdmin"),IsDomainGroup:e[0].getAttribute("IsDomainGroup"),Flags:e[0].getAttribute("Flags")})},error:function(e){var t=e.responseXML.getElementsByTagName("errorstring");r.call(i,"Error 'getUserInfo': "+t[0].firstChild.nodeValue)}}),this},whoami:function(e,t){return"function"==typeof e&&(t=e,e={}),this.people("",e,t)},addressbook:function(e,t,r){switch(arguments.length){case 1:if("object"==typeof e)return this.addressbook("",e,function(){});if("function"==typeof e)return this.addressbook("",{},e);if("string"==typeof e)return this.addressbook(e,{},function(){});e=void 0;break;case 2:if("string"==typeof e&&"function"==typeof t)return this.addressbook(e,{},t);if("object"==typeof e&&"function"==typeof t)return this.addressbook("",e,t)}if(t=t||{},void 0==t.url){if(!this.url)return this._getURL(),this._addInQueue(arguments);t.url=this.url}else this.url=t.url;t.limit=t.limit||10,t.type=t.type||"User",r=r||function(){},e=e||"";var s="<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'><soap:Body><SearchPrincipals xmlns='http://schemas.microsoft.com/sharepoint/soap/'><searchText>"+e+"</searchText><maxResults>"+t.limit+"</maxResults><principalType>"+t.type+"</principalType></SearchPrincipals></soap:Body></soap:Envelope>",i=this,o=t.url+"/_vti_bin/People.asmx";return jQuery.ajax({type:"POST",cache:!1,url:o,data:s,beforeSend:function(e){e.setRequestHeader("SOAPAction","http://schemas.microsoft.com/sharepoint/soap/SearchPrincipals")},contentType:"text/xml; charset=utf-8",dataType:"xml",success:function(e){var t=[];e=e.getElementsByTagName("PrincipalInfo");for(var s=0,o=e.length;o>s;s++){var n=e[s].childNodes;t[s]=[];for(var a=0,l=n.length;l>a;a++){var u=n[a].nodeName,c=n[a].firstChild;c&&(c=c.nodeValue),t[s].push(u),t[s][u]=c}}r.call(i,t)}}),this},reset:function(){this.data=[],this.length=0,this.listID="",this.needQueue=!1,this.listQueue=[],delete this.url},toDate:function(e,t){if(e instanceof Date)return e;if(19!=e.length&&20!=e.length)throw"toDate: '"+e+"' is invalid.";var r=e.substring(0,4),s=e.substring(5,7),i=e.substring(8,10),o=e.substring(11,13),n=e.substring(14,16),a=e.substring(17,19);return e.indexOf("Z")>-1||t?new Date(Date.UTC(r,s-1,i,o,n,a)):new Date(r,s-1,i,o,n,a)},toSPDate:function(e,t){var r=function(e){return 1==e.toString().length&&(e="0"+e),e},s=r(e.getMonth()+1),i=r(e.getDate()),o=e.getFullYear(),n=r(e.getHours()),a=r(e.getMinutes()),l=r(e.getSeconds());return o+"-"+s+"-"+i+(t?" "+n+":"+a+":"+l:"")},toCurrency:function(e,t,r){e=Number(e),void 0===t&&(t=-1),void 0===r&&(r="$");var s="";0>e&&(s="-",e*=-1);var i=e;i=-1===t?i.toFixed(2).replace(".00",""):i.toFixed(t);for(var o=(Math.floor(e)+"").length,n=0,a=0,l=o%3;o>n;n++)0!=n&&n%3==l&&(i=i.substr(0,n+a)+","+i.substr(n+a),a++);return(""!=r?r:"")+s+i+(""!=r?"":" "+r)},getLookup:function(e){if(!e)return{id:"",value:""};var t=e.split(";#");return{id:t[0],value:t[1]}},toXSLString:function(e){if("string"!=typeof e)throw"Error 'toXLSString': '"+e+"' is not a string....";var t=function(e,t){t=t||!1;for(var r=new Array("0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"),s="",i=0;i<e.length;i++){for(var o=e.charAt(i),n=o.charCodeAt(0),a=0,l="";n>=16;)a=n%16,n=Math.floor(n/16),l+=r[a];l+=r[n];for(var u="",c=l.length-1;c>=0;c--)u+=l.charAt(c);s+="%"+u}return s},r=e.split(" "),s="";/^[0-9]/.test(r[0])&&r[0].length<5&&(s=t(e.charAt(0)),e=e.substring(1));for(var i=0;i<e.length;i++){var o=e.charAt(i);s+=/[0-9A-Za-z_]/.test(o)===!1?t(o).toLowerCase():o}return s.replace(/%([a-zA-Z0-9][a-zA-Z0-9])/g,"_x00$1_").substring(0,32)},formfields:function(fields,settings){"use strict";this.reset(),1==arguments.length&&"object"==typeof fields&&"undefined"==typeof fields.length&&(settings=fields,fields=void 0),settings=settings||{},fields=fields||[],settings.cache=settings.cache===!1?!1:!0;var aReturn=[],bigLimit=1e4;"string"==typeof fields&&(fields=""===fields?[]:fields.split(","));var limit=fields.length>0?fields.length:bigLimit;if(limit!==bigLimit||settings.mandatory||(settings.includeAll=!0),settings.cache&&null!==_SP_CACHE_FORMFIELDS){var allFields=_SP_CACHE_FORMFIELDS.slice(0);if(settings.includeAll)return this.length=allFields.length,this.data=allFields,this;var done=0,i,len=allFields.length,idx,fieldNames=[];for(i=0;len>i;i++)fieldNames.push(allFields[i]._name);for(i=0;limit>i;i++)idx=fieldNames.indexOf(fields[i]),idx>-1&&aReturn.push(allFields[idx]);for(i=0,len=settings.mandatory?allFields.length:0;len>i;i++)allFields[i]._isMandatory&&-1===fields.indexOf(allFields[i]._name)&&aReturn.push(allFields[i]);return this.length=aReturn.length,this.data=aReturn,this}settings.cache&&(settings.includeAll=!0);var selectorSupported="undefined"!=typeof document.querySelector,table=null;if(selectorSupported)table=document.querySelector("table.ms-formtable");else for(var a=document.getElementsByTagName("table"),i=0,len=a.length;len>i;i++)if(a[i].className.indexOf("ms-formtable")>-1){table=a[i];break}if(!table)throw"Error: unable to find the table.ms-formtable!";var closestTR=function(e){var t=e;do t=t.parentNode;while("tr"!==t.tagName.toLowerCase());return t},getText=function(e){var t,r,s=e.nodeType,i="";if(s){if(1===s||9===s||11===s){if("string"==typeof e.textContent)return e.textContent;if("string"==typeof e.innerText)return e.innerText.replace(/\r/g,"");for(e=e.firstChild;e;e=e.nextSibling)i+=getText(e)}else if(3===s||4===s)return e.nodeValue}else for(t=0;r=e[t];t++)8!==r.nodeType&&(i+=getText(r));return i};settings.includeAll&&(limit=bigLimit);for(var a=table.getElementsByTagName("nobr"),i=-1,len=a.length,done=0;len>i&&limit>done;i++){var nobr,tr,isMandatory=!1,html,txt,includeThisField=!1,search;if(settings.includeAll&&(includeThisField=!0),-1===i)(includeThisField||fields.indexOf("Content Type")>-1)&&(txt=html="Content Type",includeThisField=!0);else{if(tr=void 0,nobr=a[i],"H3"!==nobr.parentNode.tagName.toUpperCase())continue;if(html=nobr.innerHTML,txt=getText(nobr),html.indexOf("ms-formvalidation")>-1&&(html=html.slice(0,-39),"<"!=html.charAt(html.length-2)||"s"!=html.charAt(html.length-1)&&"S"!=html.charAt(html.length-1)||(html=html.slice(0,-2)),settings.mandatory&&(includeThisField=!0),txt=txt.slice(0,-2),isMandatory=!0),limit!==bigLimit)for(var k=0,lenk=limit;lenk>k;k++)if(fields[k].trim()===txt){includeThisField=!0,done++;break}}if(includeThisField){var fieldName=txt,obj={_name:fieldName,_isMandatory:isMandatory,_description:"",_elements:null,_tr:null,_type:null};if("Content Type"===fieldName){if(selectorSupported)obj._elements=document.querySelector('.ms-formbody select[title="Content Type"]');else for(var a=document.getElementsByTagName("td"),aa=0;aa<a.length;aa++)if(a[aa].className.indexOf("ms-formbody")>-1)for(var b=document.getElementsByTagName("select"),bb=0;bb<b.length;bb++)if("Content Type"===b[bb].title){aa=a.length,obj._elements=b[bb];break}if(obj._type="content type",!obj._elements)continue;obj._tr=closestTR(obj._elements)}else obj._tr=void 0===tr?closestTR(nobr):tr;obj.val=function(){},obj.elem=function(){return this._elements},obj.description=function(){return this._description},obj.type=function(){return this._type},obj.row=function(){return this._tr},obj.name=function(){return this._name},obj.isMandatory=function(){return this._isMandatory},obj.options=function(){},tr=obj._tr.length?obj._tr[0]:obj._tr;var td=tr.getElementsByTagName("td")[1].getElementsByTagName("span")[0],elem=[];if("Attachments"===obj._name)obj._type="attachments",elem=td.getElementsByTagName("tr");else if("Content Type"===obj._name)elem=[obj._elements];else{for(var input=td.getElementsByTagName("input"),continueToSearch=!1,inp=0;inp<input.length;inp++)if("true"!==input[inp].getAttribute("data-sp-ignore")){var type=input[inp].getAttribute("type");switch(type){case"text":input[inp].className.indexOf("ms-input")>-1||input[inp].className.indexOf("ms-long")>-1?(elem.push(input[inp]),obj._type||(obj._type="text"),input[inp].id.search(/DateTimeFieldDate$/)>-1?(continueToSearch=!0,obj._type="date"):input[inp].id.search(/_UrlFieldUrl$|_UrlFieldDescription$/)>-1?(obj._type="url",elem.pop(),elem.push(input[inp].previousElementSibling||input[inp].previousSibling),elem.push(input[inp])):inp=input.length):input[inp].title.indexOf("Specify your own value:")>-1&&(elem.push(input[inp]),"choices"===obj._type.slice(0,7)&&(obj._type+=" plus"));break;case"radio":if(input[inp].id.search(/_DropDownButton$/)>-1){obj._type="choices plus";do elem.push(input[inp]),inp||elem.push("");while(++inp<input.length);continueToSearch=!0}else elem.push(input[inp]),elem.push(input[inp].nextSibling),obj._type="choices radio";break;case"checkbox":elem.push(input[inp]),obj._type=input[inp].id.search(/_BooleanField$/)>-1?"boolean":"choices checkbox","boolean"!==obj._type&&elem.push(input[inp].nextSibling)}}if(0===elem.length||continueToSearch){var select=td.getElementsByTagName("select");for(inp=0;inp<select.length;inp++)if(select[inp].className.indexOf("ms-RadioText")>-1||select[inp].id.search(/_cbRate$|_Lookup$|_SelectResult$|_SelectCandidate$|_DateTimeFieldDateHours$|_DateTimeFieldDateMinutes$/)>-1){if(!(select[inp].id.search(/_SelectCandidate$|_SelectResult$|_DateTimeFieldDateHours$|_DateTimeFieldDateMinutes$/)>-1)){continueToSearch?"choices plus"===obj._type?elem[1]=select[inp]:elem.push(select[inp]):(elem.push(select[inp]),select[inp].id.search(/_Lookup$/)>-1?obj._type="lookup":obj._type||(obj._type="choices"));break}if(select[inp].id.indexOf("DateTimeField")>-1&&(obj._type="date time"),elem.push(select[inp]),select[inp].id.indexOf("_SelectCandidate")>-1){var buttons=td.getElementsByTagName("button");2===buttons.length&&(elem.push(buttons[0]),elem.push(buttons[1]),obj._type="lookup multiple")}}}if(0===elem.length){var other=td.getElementsByTagName("div");for(inp=0;inp<other.length;inp++)if(other[inp].className.indexOf("ms-inputuserfield")>-1){elem.push(other[inp]),obj._type="people";break}for(other=td.getElementsByTagName("textarea"),inp=0;inp<other.length;inp++)if(other[inp].className.indexOf("ms-long")>-1||other[inp].className.indexOf("ms-input")>-1){if(elem.push(other[inp]),obj._type){if("people"===obj._type){for(other=td.getElementsByTagName("a"),inp=0;inp<other.length;inp++)elem.push(other[inp]);break}}else obj._type="text multiple";if(other=other[inp].nextSibling,!(other&&other.className&&other.className.indexOf("ms-rtetoolbarmenu")>-1)){for(other=td.getElementsByTagName("span"),inp=other.length;inp--;)if(other[inp].className.indexOf("ms-formdescription")>-1){elem.push(other[inp]);break}break
}elem=td.getElementsByTagName("iframe")}}if(td.nextSibling){var descro=td.nextSibling;3==descro.nodeType&&(obj._description=getText(descro).trim())}}switch(obj._elements=elem,obj.type()){case"attachments":obj.val=function(e){if(!e){var t=this.elem(),r=[];for(e=0;e<t.length;e++)r.push(getText(t[e]).slice(0,-6).trim());return r}alert("$SP.formfields Error: You cannot define a value for the Attachments")};break;case"date":case"text":case"text multiple":obj.val=function(e){var t=this.elem(),r=this.type();if("iframe"===t[0].tagName.toLowerCase()){var s=1===t.length?t[0]:t[1],i=s.contentDocument?s.contentDocument:s.contentWindow.document;if(!e)return i.getElementsByTagName("div")[0].innerHTML;i.getElementsByTagName("div")[0].innerHTML=e}else{if(void 0===e)return t[0].value;t[0].value=e,"text multiple"===r&&(t[0].innerHTML=e)}return this};break;case"date time":obj.val=function(e){var t=[],r=this.elem();if(void 0===e){for(var s=0;s<r.length;s++)if("input"===r[s].tagName.toLowerCase())t.push(r[s].value);else for(var i=r[s].getElementsByTagName("option"),o=i.length;o--;)if(i[o].selected){t.push(i[o].value);break}return t}"string"==typeof e&&(e=[e]),r[0].value=e[0];for(var n=1;3>n;n++)if(e[n])for(var i=r[n].getElementsByTagName("option"),s=i.length;s--;)i[s].value===e[n]&&(i[s].selected=!0);return this};break;case"url":obj.val=function(e){void 0!==e&&("string"==typeof e?e=[e,e]:1===e.length&&(e=[e[0],e[0]]));for(var t=[],r=this.elem(),s=0,i=0;s<r.length;s++)"input"===r[s].tagName.toLowerCase()&&(void 0!==e?r[s].value=e[i++]:t.push(r[s].value));return void 0!==e?this:t};break;case"boolean":obj.val=function(e){return"boolean"==typeof e?(this.elem()[0].checked=e,this):this.elem()[0].checked};break;case"people":obj.val=function(e){var t=this.elem();if(void 0!==e)return t[0].innerHTML=e,t[1].value=e,this;e=t[0].innerHTML.replace(/(<([^>]+)>)/gi,"").replace(/^\s+|\s+$| /g,"").replace(/<br>| /g,"").replace(/;$/,"").split(";");for(var r=[],s=0;s<e.length;s++)e[s]=e[s].trim(),""!==e[s]&&r.push(e[s]);return 1===r.length?r[0]:0===r.length?"":r};break;case"content type":obj.val=function(v){for(var e=this.elem(),options=e[0].getElementsByTagName("option"),i=0;i<options.length;i++){if(v==options[i].value||v==options[i].innerHTML)return options[i].selected=!0,eval("!function() {"+e[0].getAttribute("onchange").replace(/javascript:/,"")+"}()"),this;if(!v&&options[i].selected)return options[i].innerHTML}return this},obj.options=function(){for(var e=[],t=this.elem(),r=t[0].getElementsByTagName("option"),s=0;s<r.length;s++)e.push(r[s].value+";#"+r[s].innerHTML);return e};break;case"lookup":case"choices":case"choices plus":obj.val=function(e){for(var t=this.elem(),r=this.type(),s="plus"===r.slice(-4)?t[1].getElementsByTagName("option"):t[0].getElementsByTagName("option"),i=0;i<s.length;i++){if(e==s[i].value||e==s[i].innerHTML)return s[i].selected=!0,"choices plus"===r&&(t[0].checked=!0),this;if(void 0===e&&s[i].selected&&("lookup"===r||"choices"===r||"choices plus"===r&&t[0].checked))return s[i].innerHTML}if("choices plus"===r&&4===t.length)if(void 0!==e)t[2].checked=!0,t[3].value=e;else if(t[2].checked)return t[3].value},obj.options=function(){for(var e=[],t=this.elem(),r=this.type(),s="plus"===r.slice(-4)?t[1].getElementsByTagName("option"):t[0].getElementsByTagName("option"),i=0;i<s.length;i++)e.push(s[i].value+("lookup"===r?";#"+s[i].innerHTML:""));return"choices plus"===r&&4===t.length&&""!=t[3].value&&e.push(t[3].value),e};break;case"lookup multiple":obj.val=function(v){var e=this.elem(),type=this.type(),options,i;if("string"==typeof v&&(v=[v]),void 0!==v){var optValues=[],optText=[],idx;for(options=e[3].getElementsByTagName("option"),i=0;i<options.length;i++)options[i].selected=!0;for(eval("!function() {"+e[2].getAttribute("onclick")+"}()"),options=e[0].getElementsByTagName("option"),idx=0;idx<options.length;idx++)options[idx].selected=!1;for(i=0;i<v.length;i++)for(idx=0;idx<options.length;idx++)if(options[idx].innerHTML==v[i]||options[idx].value==v[i]){options[idx].selected=!0,eval("!function() {"+e[1].getAttribute("onclick")+"}()"),options=e[0].getElementsByTagName("option");break}return this}var ret=[];for(options=e[3].getElementsByTagName("option"),i=0;i<options.length;i++)ret.push(options[i].innerHTML);return ret},obj.options=function(){var e=[],t=this.elem(),r=t[0].getElementsByTagName("option");for(i=0;i<r.length;i++)e.push(r[i].value+";#"+r[i].innerHTML);for(r=t[3].getElementsByTagName("option"),i=0;i<r.length;i++)e.push(r[i].value+";#"+r[i].innerHTML);return e};break;case"choices radio":case"choices radio plus":case"choices checkbox":case"choices checkbox plus":obj.val=function(e){var t=this.elem(),r=this.type(),s=[],i=[];"string"==typeof e&&(e=[e]);for(var o=0;o<t.length;o++)if(void 0!==e&&"label"===t[o].tagName.toLowerCase()&&e.indexOf(t[o].innerHTML)>-1){if(t[o-1].checked=!0,i.push(t[o].innerHTML),"choices radio"===r.slice(0,13))return this}else if(void 0!==e&&"label"===t[o].tagName.toLowerCase())t[o-1].checked=!1;else if(void 0===e&&t[o].checked){if("choices radio plus"===r)return"Specify your own value:"===t[o+1].innerHTML?t[o+2].value:t[o+1].innerHTML;s.push("Specify your own value:"===t[o+1].innerHTML?t[o+2].value:t[o+1].innerHTML)}if(void 0===e)return s;if(void 0!==e){if("choices radio plus"===r)t[t.length-3].checked=!0,t[t.length-1].value=e;else if("choices checkbox plus"===r){for(var n=[],o=e.length;o--;)-1===i.indexOf(e[o])&&n.push(e[o]);n.length>0&&(t[t.length-3].checked=!0,t[t.length-1].value=n.join(" "))}return this}},obj.options=function(){for(var e=this.elem(),t=[],r=this.type().slice(-4),s=0;s<e.length;s++)if("label"===e[s].tagName.toLowerCase()){if("Specify your own value:"===e[s].innerHTML&&"plus"===r)continue;t.push(e[s].innerHTML)}else"plus"===r&&"text"===e[s].type&&""!=e[s].value&&t.push(e[s].value);return t}}aReturn.push(obj)}}return settings.cache?(_SP_CACHE_FORMFIELDS=aReturn.slice(0),settings.includeAll=!1,this.formfields(fields,settings)):(this.length=aReturn.length,this.data=aReturn,this)},each:function(e){for(var t=0,r=this.data.length;r>t;t++)e.call(this.data[t]);return this},val:function(e){if("object"==typeof e&&void 0!==e.identity?(identity=e.identity,e=void 0):identity=!1,void 0===e){var t=[];return this.each(function(){identity?t[this.name()]=this.val():t.push(this.val())}),1===t.length?t[0]:t}if("object"!=typeof e)this.each(function(){this.val(e)});else{var r=0;if(this.length>1){if(e.length!==this.length)throw new Error("$SP.formfields.val: the array passed for val() must have the same size as the number of fields in formfields()");this.each(function(){this.val(e[r++])})}else this.each(function(){this.val(e)})}return this},elem:function(){var e=[],t="function"==typeof jQuery;switch(this.each(function(){var t=this.elem();e.push(1===t.length?t[0]:t)}),e.length){case 0:return t?jQuery():null;case 1:return t?jQuery(e[0]):e[0];default:return t?jQuery(e):e}},row:function(){var e=[],t="function"==typeof jQuery;switch(this.each(function(){e.push(this.row())}),e.length){case 0:return t?jQuery():null;case 1:return t?jQuery(e[0]):e[0];default:return t?jQuery(e):e}},type:function(){var e=[];switch(this.each(function(){e.push(this.type())}),e.length){case 0:return"";case 1:return e[0];default:return e}},description:function(){var e=[];switch(this.each(function(){e.push(this.description())}),e.length){case 0:return"";case 1:return e[0];default:return e}},notify:function(e,t){if(void 0===e)throw"Error 'notify': you must provide the message to show.";if("string"!=typeof e)throw"Error 'notify': you must provide a string for the message to show.";if(t=t||{},t.timeout=isNaN(t.timeout)?5:t.timeout,t.override=t.override===!0?!0:!1,t.overrideAll=t.overrideAll===!0?!0:!1,t.overrideSticky=t.overrideSticky===!1?!1:!0,t.sticky=t.sticky===!0?!0:!1,t.name=t.name||(new Date).getTime(),t.after=t.after||function(){},t.fake=t.fake===!0?!0:!1,t.ignoreQueue=t.ignoreQueue===!0?!0:!1,__SP_NOTIFY_READY===!1)return __SP_NOTIFY_QUEUE.push({message:e,options:t}),$(document).ready(function(){ExecuteOrDelayUntilScriptLoaded(function(){ExecuteOrDelayUntilScriptLoaded(function(){__SP_NOTIFY_READY=!0,$SP().notify("fake",{fake:!0})},"core.js")},"sp.js")}),this;if(t.ignoreQueue!==!0)for(;__SP_NOTIFY_QUEUE.length>0;){var r=__SP_NOTIFY_QUEUE.shift();r.options.ignoreQueue=!0,$SP().notify(r.message,r.options)}if(t.fake!==!0){if(__SP_NOTIFY.length>0&&(t.overrideAll?$SP().removeNotify({all:!0,includeSticky:t.overrideSticky}):t.override&&$SP().removeNotify(__SP_NOTIFY[__SP_NOTIFY.length-1].name)),__SP_NOTIFY.push({name:t.name,id:SP.UI.Notify.addNotification(e,!0),options:t}),!t.sticky){setTimeout(function(){$SP().removeNotify(t.name,{timeout:!0})},1e3*t.timeout)}return this}},removeNotify:function(e,t){switch(arguments.length){case 0:throw"Error 'removeNotify': you must provide 'name' or 'options'.";case 2:if("object"!=typeof t)throw"Error 'removeNotify': you must provide an object for 'options'."}if(1===arguments.length&&"object"==typeof e&&(t=e,e=void 0),t=t||{all:!1},t.timeout=t.timeout===!0?!0:!1,__SP_NOTIFY_READY===!1&&__SP_NOTIFY_QUEUE.length>0)return setTimeout(function(){$SP().removeNotify(e,t)},150),this;var r,s=this;if(t.all===!0){for(var i=[];__SP_NOTIFY.length>0;)r=__SP_NOTIFY.shift(),t.includeSticky===!1&&r.options.sticky===!0?i.push(r):(SP.UI.Notify.removeNotification(r.id),setTimeout(function(){r.options.after.call(s,r.name,!1)},150));__SP_NOTIFY=i.slice(0)}else if(void 0!==e)for(var o=0,n=__SP_NOTIFY.length;n>o;o++)if(__SP_NOTIFY[o].name==e)return r=__SP_NOTIFY.splice(o,1)[0],SP.UI.Notify.removeNotification(r.id),setTimeout(function(){r.options.after.call(s,r.name,t.timeout)},150),this;return this},registerPlugin:function(e,t){var r=$("html"),s=r.data("sp-plugins")||[];if("undefined"!=typeof s[e])throw"Error 'registerPlugin': '"+e+"' is already registered.";return s[e]=t,r.data("sp-plugins",s),!0},plugin:function(e,t){var r=$("html").data("sp-plugins")||[];if(t=t||{},"function"!=typeof r[e])throw"Error $SP().plugin: the plugin '"+e+"' is not registered.";return r[e].call(this,t),this}};var myElem=function(){var e=function(e){return new t(e)},t=function(e){return this.mynode=e,this.singleList=!0,this};return e.fn=t.prototype={getAttribute:function(e){return this.mynode.getAttribute("ows_"+e.replace(/ /g,""))},getAttributes:function(){return this.mynode.attributes}},e}(),extendMyObject=function(e){this.attributes=e};return extendMyObject.prototype.getAttribute=function(e){return this.attributes[e]},extendMyObject.prototype.getAttributes=function(){return this.attributes},SharepointPlus.prototype.noConflict=function(){window._$SP=window._SharepointPlus=window.$SP},window.$SP=window.SharepointPlus=SharepointPlus}(window);