forked from signalpoint/jDrupal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jdrupal.min.js
2 lines (2 loc) · 35.7 KB
/
jdrupal.min.js
1
2
function drupal_init(){try{jDrupal||(jDrupal={}),jDrupal.csrf_token=!1,jDrupal.sessid=null,jDrupal.user=drupal_user_defaults(),jDrupal.settings={app_directory:"app",base_path:"/",cache:{entity:{enabled:!1,expiration:3600},views:{enabled:!1,expiration:3600}},debug:!1,endpoint:"",file_public_path:"sites/default/files",language_default:"und",site_path:""},jDrupal.includes={},jDrupal.includes.module={},jDrupal.modules={core:{},contrib:{},custom:{}},jDrupal.services_queue={comment:{retrieve:{}},file:{retrieve:{}},node:{retrieve:{}},taxonomy_term:{retrieve:{}},taxonomy_vocabulary:{retrieve:{}},user:{retrieve:{}}},jDrupal.cache_expiration=window.localStorage.getItem("cache_expiration"),jDrupal.cache_expiration?jDrupal.cache_expiration=JSON.parse(jDrupal.cache_expiration):jDrupal.cache_expiration={entities:{}}}catch(a){console.log("drupal_init - "+a)}}function date(a){try{var b=null,c=null;arguments[1]?(c=arguments[1],"string"==typeof c&&(c=parseInt(c)),b=new Date(c)):(b=new Date,c=b.getTime());for(var d="",e=!1,f=0;f<a.length;f++){var g=a.charAt(f);if(e)d+=g,e=!1;else switch(g){case"\\":e=!0;break;case"d":var h=""+b.getDate();1==h.length&&(h="0"+h),d+=h;break;case"D":var h=b.getDay();switch(h){case 0:d+="Sun";break;case 1:d+="Mon";break;case 2:d+="Tue";break;case 3:d+="Wed";break;case 4:d+="Thu";break;case 5:d+="Fri";break;case 6:d+="Sat"}break;case"j":d+=b.getDate();break;case"l":var h=b.getDay();switch(h){case 0:d+="Sunday";break;case 1:d+="Monday";break;case 2:d+="Tuesday";break;case 3:d+="Wednesday";break;case 4:d+="Thursday";break;case 5:d+="Friday";break;case 6:d+="Saturday"}break;case"N":d+=b.getDay()+1;break;case"w":d+=b.getDay();break;case"F":switch(b.getMonth()){case 0:d+="January";break;case 1:d+="February";break;case 2:d+="March";break;case 3:d+="April";break;case 4:d+="May";break;case 5:d+="June";break;case 6:d+="July";break;case 7:d+="August";break;case 8:d+="September";break;case 9:d+="October";break;case 10:d+="November";break;case 11:d+="December"}break;case"m":var i=""+(b.getMonth()+1);1==i.length&&(i="0"+i),d+=i;break;case"M":switch(b.getMonth()){case 0:d+="Jan";break;case 1:d+="Feb";break;case 2:d+="Mar";break;case 3:d+="Apr";break;case 4:d+="May";break;case 5:d+="Jun";break;case 6:d+="Jul";break;case 7:d+="Aug";break;case 8:d+="Sep";break;case 9:d+="Oct";break;case 10:d+="Nov";break;case 11:d+="Dec"}break;case"Y":d+=b.getFullYear();break;case"a":case"A":var j=b.getHours();d+=12>j?"am":"pm","A"==g&&(d=d.toUpperCase());break;case"g":var j=b.getHours();0==j||23==j?j=12:j%=12,d+=""+j;break;case"G":var j=""+b.getHours();d+=j;break;case"h":var j=""+b.getHours()%12;"0"==j?j="12":1==j.length&&(j="0"+j),d+=j;break;case"H":var j=""+b.getHours();1==j.length&&(j="0"+j),d+=j;break;case"i":var k=""+b.getMinutes();1==k.length&&(k="0"+k),d+=k;break;case"s":var l=""+b.getSeconds();1==l.length&&(l="0"+l),d+=l;break;default:d+=g}}return d}catch(m){console.log("date - "+m)}}function dpm(a){try{"undefined"!=typeof a?("function"==typeof parent.window.ripple?"undefined"!=typeof arguments[1]&&0==arguments[1]?console.log(JSON.stringify(a)):console.log(a):"object"==typeof a&&console.log(JSON.stringify(a)),""==a?console.log("<empty-string>"):console.log(a)):console.log("<undefined>")}catch(b){console.log("dpm - "+b)}}function drupal_user_defaults(){try{return{uid:"0",roles:{1:"anonymous user"},permissions:[]}}catch(a){console.log("drupal_user_defaults - "+a)}}function empty(a){try{return null===a?!0:"object"==typeof a?0===Object.keys(a).length:"undefined"==typeof a||""==a}catch(b){console.log("empty - "+b)}}function function_exists(name){try{return"function"==eval("typeof "+name)}catch(error){alert("function_exists - "+error)}}function http_status_code_title(a){try{var b="";switch(a){case 200:b="OK";break;case 401:b="Unauthorized";break;case 404:b="Not Found";break;case 406:b="Not Acceptable";break;case 500:b="Internal Server Error"}return b}catch(c){console.log("http_status_code_title - "+c)}}function in_array(a,b){try{if("undefined"==typeof b)return!1;if("string"==typeof a)return b.indexOf(a)>-1;for(var c=!1,d=0;d<b.length;d++)if(b[d]==a){c=!0;break}return c}catch(e){console.log("in_array - "+e)}}function is_array(a){return"[object Array]"===Object.prototype.toString.call(a)}function is_int(a){return"string"==typeof a&&(a=parseInt(a)),"number"==typeof a&&a%1==0}function language_default(){try{return jDrupal.settings.language_default&&""!=jDrupal.settings.language_default?jDrupal.settings.language_default:"und"}catch(a){console.log("language_default - "+a)}}function module_exists(a){try{var b=!1;return"undefined"!=typeof jDrupal.modules.core[a]?b=!0:"undefined"!=typeof jDrupal.modules.contrib[a]?b=!0:"undefined"!=typeof jDrupal.modules.custom[a]&&(b=!0),b}catch(c){console.log("module_exists - "+c)}}function shuffle(a){try{for(var b=a.length-1;b>0;b--){var c=Math.floor(Math.random()*(b+1)),d=a[b];a[b]=a[c],a[c]=d}return a}catch(e){console.log("shuffle - "+e)}}function time(){var a=new Date;return Math.floor(a/1e3)}function ucfirst(a){a+="";var b=a.charAt(0).toUpperCase();return b+a.substr(1)}function module_implements(a){try{var b=[];if(a)for(var c=module_types(),d=0;d<c.length;d++){var e=c[d];for(var f in jDrupal.modules[e])jDrupal.modules[e].hasOwnProperty(f)&&function_exists(f+"_"+a)&&b.push(f)}return 0==b.length?!1:b}catch(g){console.log("module_implements - "+g)}}function module_invoke(a,b){try{var c=null;if(module_load(a)){var d=Array.prototype.slice.call(arguments),e=a+"_"+b;if(function_exists(e)){var f=window[e];d.splice(0,2),c=0==Object.getOwnPropertyNames(d).length?f():f.apply(null,d)}}else console.log("WARNING: module_invoke() - Failed to load module: "+a);return c}catch(g){console.log("module_invoke - "+g)}}function module_invoke_all(a){try{module_invoke_results=new Array;var b=Array.prototype.slice.call(arguments);b.splice(0,1),module_invoke_continue=!0;for(var c=module_types(),d=0;d<c.length;d++){var e=c[d];for(var f in jDrupal.modules[e])if(jDrupal.modules[e].hasOwnProperty(f)){var g=f+"_"+a;if(function_exists(g)){var h=null;if(0==b.length)h=module_invoke(f,a);else{b.unshift(f,a);var i=window.module_invoke;h=i.apply(null,b),b.splice(0,2)}"undefined"!=typeof h&&module_invoke_results.push(h)}}}return module_invoke_results}catch(j){console.log("module_invoke_all - "+j)}}function module_load(a){try{for(var b=module_types(),c=0;c<b.length;c++){var d=b[c];if(jDrupal.modules[d][a])return jDrupal.modules[d][a]}return!1}catch(e){console.log("module_load - "+e)}}function module_object_template(a){try{return{name:a}}catch(b){console.log("module_object_template - "+b)}}function module_types(){try{return["core","contrib","custom"]}catch(a){console.log("module_types - "+a)}}function comment_load(a,b){try{entity_load("comment",a,b)}catch(c){console.log("comment_load - "+c)}}function comment_save(a,b){try{entity_save("comment",null,a,b)}catch(c){console.log("comment_save - "+c)}}function services_entity_types(){var a=[];if(jDrupal.services_entity&&jDrupal.services_entity.types)for(var b in jDrupal.services_entity.types)jDrupal.services_entity.types.hasOwnProperty(b)&&a.push(b);return a}function _services_entity_queue_init(){for(var a in jDrupal.services_entity.types)jDrupal.services_entity.types.hasOwnProperty(a)&&(jDrupal.services_queue[a]||(jDrupal.services_queue[a]={retrieve:{}}))}function entity_get_bundle(a,b){try{var c=null;switch(a){case"node":c=b.type;break;case"taxonomy_term":c=b.vid;break;case"comment":case"file":case"user":case"taxonomy_vocabulary":break;default:if(in_array(a,services_entity_types()))return b.type;var d="WARNING: entity_get_bundle - unsupported entity type ("+a+")";console.log(d)}return c}catch(e){console.log("entity_get_bundle - "+e)}}function entity_get_bundle_name(a){switch(a){case"node":return"type";case"taxonomy_term":return"vid";case"comment":case"file":case"user":case"taxonomy_vocabulary":default:return in_array(a,services_entity_types())?"type":null}}function entity_id_parse(a){return"string"==typeof a?parseInt(a):a}function entity_local_storage_key(a,b){return a+"_"+b}function entity_index_local_storage_key(a){return a}function entity_load(a,b,c){try{var d=in_array(a,services_entity_types());if(d&&_services_entity_queue_init(),is_array(b)){var e={parameters:{},options:{entity_load:!0}};return e.parameters[entity_primary_key(a)]=b.join(","),void window[a+"_index"](e,c)}var f=b;f=entity_id_parse(f);var g=entity_caching_enabled(a);if(_services_queue_already_queued(a,"retrieve",f,"success"))return g&&(h=_entity_local_storage_load(a,f,c))?void(c.success&&c.success(h)):("undefined"!=typeof c.success&&_services_queue_callback_add(a,"retrieve",f,"success",c.success),void("undefined"!=typeof c.error&&_services_queue_callback_add(a,"retrieve",f,"error",c.error)));_services_queue_add_to_queue(a,"retrieve",f),_services_queue_callback_add(a,"retrieve",f,"success",c.success);var h=!1;if(g&&(h=_entity_local_storage_load(a,f,c)))return void _entity_callback_bubble(a,f,h);if(!in_array(a,entity_types())){var i="WARNING: entity_load - unsupported type: "+a;return console.log(i),void(c.error&&c.error(null,null,i))}var j=entity_primary_key(a),k={success:function(b){try{h=b,entity_caching_enabled(a,entity_get_bundle(a,h))&&(_entity_set_expiration_time(a,h),_entity_local_storage_save(a,f,h)),_entity_callback_bubble(a,f,h)}catch(c){console.log("entity_load - success - "+c)}},error:function(b,d,e){try{_services_queue_clear(a,"retrieve",f,"success"),c.error&&c.error(b,d,e)}catch(g){console.log("entity_load - error - "+g)}}},l=d?"entity_retrieve":a+"_retrieve";if(function_exists(l)){k[j]=f;var m=window[l];d?(services_resource_defaults(k,a,"retrieve"),m(a,b,k)):m(b,k)}else console.log("WARNING: "+l+"() does not exist!")}catch(n){console.log("entity_load - "+n)}}function _entity_callback_bubble(a,b,c){for(var d=jDrupal.services_queue[a].retrieve[b].success,e=0;e<d.length;e++)d[e](c);_services_queue_clear(a,"retrieve",b,"success")}function _entity_local_storage_load(a,b,c){try{var d=!1;c&&c.reset&&_entity_local_storage_delete(a,b);var e=entity_local_storage_key(a,b);if(d=window.localStorage.getItem(e))if(d=JSON.parse(d),entity_has_expired(a,d))_entity_local_storage_delete(a,b),d=!1;else if(drupalgap&&drupalgap.page.options&&drupalgap.page.options.reloadingPage){if("undefined"!=typeof drupalgap.page.options.reset&&drupalgap.page.options.reset===!1)return d;_entity_local_storage_delete(a,b),d=!1}return d}catch(f){console.log("_entity_local_storage_load - "+f)}}function _entity_local_storage_save(a,b,c){try{var d=entity_local_storage_key(a,b);window.localStorage.setItem(d,JSON.stringify(c)),"undefined"==typeof jDrupal.cache_expiration.entities&&(jDrupal.cache_expiration.entities={}),jDrupal.cache_expiration.entities[d]=c.expiration,window.localStorage.setItem("cache_expiration",JSON.stringify(jDrupal.cache_expiration))}catch(e){console.log("_entity_local_storage_save - "+e)}}function _entity_local_storage_delete(a,b){try{var c=entity_local_storage_key(a,b);window.localStorage.removeItem(c)}catch(d){console.log("_entity_local_storage_delete - "+d)}}function entity_primary_key(a){try{var b;switch(a){case"comment":b="cid";break;case"file":b="fid";break;case"node":b="nid";break;case"taxonomy_term":b="tid";break;case"taxonomy_vocabulary":b="vid";break;case"user":b="uid";break;default:if(in_array(a,services_entity_types()))return"id";var c=a+"_primary_key";if(function_exists(c)){var d=window[c];b=d(a)}else{var e="entity_primary_key - unsupported entity type ("+a+") - to add support, declare "+c+"() and have it return the primary key column name as a string";console.log(e)}}return b}catch(f){console.log("entity_primary_key - "+f)}}function entity_save(a,b,c,d){try{var e;switch(a){case"comment":e=c.cid?"comment_update":"comment_create";break;case"file":e="file_create";break;case"node":c.language||(c.language=language_default()),e=c.nid?"node_update":"node_create";break;case"user":e=c.uid?"user_update":"user_create";break;case"taxonomy_term":e=c.tid?"taxonomy_term_update":"taxonomy_term_create";break;case"taxonomy_vocabulary":e=c.vid?"taxonomy_vocabulary_update":"taxonomy_vocabulary_create";break;default:if(in_array(a,services_entity_types()))return e=c[entity_primary_key(a)]?"entity_update":"entity_create",void window[e](a,b,c,d)}if(e&&function_exists(e)){var f=window[e];f(c,d)}else console.log("WARNING: entity_save - unsupported type: "+a)}catch(g){console.log("entity_save - "+g)}}function entity_caching_enabled(){try{if("undefined"==typeof jDrupal.settings.cache||"undefined"==typeof jDrupal.settings.cache.entity||!jDrupal.settings.cache.entity.enabled)return!1;var a=arguments[0];if(!a)return!0;if(!jDrupal.settings.cache.entity.entity_types||!jDrupal.settings.cache.entity.entity_types[a])return!0;var b=jDrupal.settings.cache.entity.entity_types[a],c="undefined"!=typeof b.enabled&&b.enabled===!1;if(c)return!1;var d=arguments[1];return d&&"undefined"!=typeof b.bundles&&"undefined"!=typeof b.bundles[d]?"undefined"!=typeof b.bundles[d].enabled?b.bundles[d].enabled:b.enabled:!0}catch(e){console.log("entity_caching_enabled - "+e)}}function entity_has_expired(a,b){return"undefined"!=typeof b.expiration&&0!=b.expiration&&time()>b.expiration}function entity_clean_local_storage(){if(jDrupal.cache_expiration.entities)for(var a in jDrupal.cache_expiration.entities)if(jDrupal.cache_expiration.entities.hasOwnProperty(a)){var b=jDrupal.cache_expiration.entities[a];if(!(b>time())){delete jDrupal.cache_expiration.entities[a];var c=a.split("_"),d=c[0],e=c[1];_entity_local_storage_delete(d,e),window.localStorage.setItem("cache_expiration",JSON.stringify(jDrupal.cache_expiration))}}}function _entity_get_expiration_time(a,b){try{var c=null,d=entity_get_bundle(a,b);if(entity_caching_enabled(a,d)){var c=0,e=jDrupal.settings.cache;"undefined"!==e.entity.expiration&&(c=e.entity.expiration),"undefined"!==e.entity.entity_types&&(e.entity.entity_types[a]&&"undefined"!=typeof e.entity.entity_types[a].expiration&&(c=e.entity.entity_types[a].expiration),d&&e.entity.entity_types[a]&&e.entity.entity_types[a].bundles&&e.entity.entity_types[a].bundles[d]&&"undefined"!=typeof e.entity.entity_types[a].bundles[d].expiration&&(c=e.entity.entity_types[a].bundles[d].expiration))}return c&&(c+=time()),c}catch(f){console.log("_entity_get_expiration_time - "+f)}}function _entity_set_expiration_time(a,b){try{b.expiration=_entity_get_expiration_time(a,b)}catch(c){console.log("_entity_set_expiration_time - "+c)}}function entity_types(){var a=["comment","file","node","taxonomy_term","taxonomy_vocabulary","user"],b=services_entity_types();return b.length&&a.push.apply(a,b),a}function _entity_index_local_storage_load(a,b,c){try{var d=!1;c&&c.reset&&_entity_index_local_storage_delete(b);var e=entity_index_local_storage_key(b);if(d=window.localStorage.getItem(e))if(d=JSON.parse(d),"undefined"!=typeof d.expiration&&0!=d.expiration&&time()>d.expiration)_entity_index_local_storage_delete(b),d=!1;else{for(var f=[],g=0;g<d.entity_ids.length;g++)f.push(_entity_local_storage_load(a,d.entity_ids[g],c));d=f}return d}catch(h){console.log("_entity_index_local_storage_load - "+h)}}function _entity_index_local_storage_save(a,b,c){try{for(var d={entity_type:a,expiration:_entity_get_expiration_time(),entity_ids:[]},e=0;e<c.length;e++)d.entity_ids.push(c[e][entity_primary_key(a)]);window.localStorage.setItem(entity_index_local_storage_key(b),JSON.stringify(d))}catch(f){console.log("_entity_index_local_storage_save - "+f)}}function _entity_index_local_storage_delete(a){try{var b=entity_index_local_storage_key(a);window.localStorage.removeItem(b)}catch(c){console.log("_entity_index_local_storage_delete - "+c)}}function file_load(a,b){try{entity_load("file",a,b)}catch(c){console.log("file_load - "+c)}}function file_save(a,b){try{entity_save("file",null,a,b)}catch(c){console.log("file_save - "+c)}}function node_load(a,b){try{entity_load("node",a,b)}catch(c){console.log("node_load - "+c)}}function node_save(a,b){try{entity_save("node",a.type,a,b)}catch(c){console.log("node_save - "+c)}}function taxonomy_term_load(a,b){try{entity_load("taxonomy_term",a,b)}catch(c){console.log("taxonomy_term_load - "+c)}}function taxonomy_term_save(a,b){try{entity_save("taxonomy_term",null,a,b)}catch(c){console.log("taxonomy_term_save - "+c)}}function taxonomy_vocabulary_load(a,b){try{entity_load("taxonomy_vocabulary",a,b)}catch(c){console.log("taxonomy_vocabulary_load - "+c)}}function taxonomy_vocabulary_save(a,b){try{entity_save("taxonomy_vocabulary",null,a,b)}catch(c){console.log("taxonomy_vocabulary_save - "+c)}}function user_load(a,b){try{entity_load("user",a,b)}catch(c){console.log("user_load - "+c)}}function user_save(a,b){try{entity_save("user",null,a,b)}catch(c){console.log("user_save - "+c)}}function user_password(){try{var a=10;arguments[0]&&(a=arguments[0]);for(var b="",c="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz23456789",d=0;a>d;d++)b+=c.charAt(Math.floor(Math.random()*c.length));return b}catch(e){console.log("user_password - "+e)}}function services_get_csrf_token(a){try{var b;if(a.reset&&(jDrupal.sessid=null),jDrupal.sessid&&(b=jDrupal.sessid),b)return void(a.success&&a.success(b));var c=new XMLHttpRequest;a.token_url=jDrupal.settings.site_path+jDrupal.settings.base_path+"?q=services/session/token",module_invoke_all("csrf_token_preprocess",a),c.onreadystatechange=function(){4==c.readyState&&0==c.status&&a.error&&a.error(c,0,"xhr network status problem for csrf token")},c.onload=function(d){try{if(4==c.readyState){c.status+" - "+http_status_code_title(c.status);200!=c.status?a.error&&a.error(c,c.status,c.responseText):(b=c.responseText.trim(),jDrupal.sessid=b,a.success&&a.success(b))}else console.log("services_get_csrf_token - readyState - "+c.readyState)}catch(e){console.log("services_get_csrf_token - token_request. onload - "+e)}},c.open("GET",a.token_url,!0),c.send(null)}catch(d){console.log("services_get_csrf_token - "+d)}}function services_ready(){try{var a=!0;return""==jDrupal.settings.site_path&&(a=!1,console.log("jDrupal's jDrupal.settings.site_path is not set!")),""==jDrupal.settings.endpoint&&(a=!1,console.log("jDrupal's jDrupal.settings.endpoint is not set!")),a}catch(b){console.log("services_ready - "+b)}}function services_resource_defaults(a,b,c){a.service||(a.service=b),a.resource||(a.resource=c)}function _services_queue_already_queued(a,b,c,d){try{var e=!1;if("undefined"!=typeof jDrupal.services_queue[a][b][c]){var f=jDrupal.services_queue[a][b][c];0!=f[d].length&&(e=!0)}return e}catch(g){console.log("_services_queue_already_queued - "+g)}}function _services_queue_add_to_queue(a,b,c){try{jDrupal.services_queue[a][b][c]={entity_id:c,success:[],error:[]}}catch(d){console.log("_services_queue_add_to_queue - "+d)}}function _services_queue_clear(a,b,c,d){try{jDrupal.services_queue[a].retrieve[c][d]=[]}catch(e){console.log("_services_queue_clear - "+e)}}function _services_queue_remove_from_queue(a,b,c){console.log("WARNING: services_queue_remove_from_queue() not done yet!")}function _services_queue_callback_add(a,b,c,d,e){try{jDrupal.services_queue[a][b][c][d].push(e)}catch(f){console.log("_services_queue_callback_add - "+f)}}function _services_queue_callback_count(a,b,c,d){try{var e=jDrupal.services_queue[a][b][c][d].length;return e}catch(f){console.log("_services_queue_callback_count - "+f)}}function comment_create(a,b){try{services_resource_defaults(b,"comment","create"),entity_create("comment",null,a,b)}catch(c){console.log("comment_create - "+c)}}function comment_retrieve(a,b){try{services_resource_defaults(b,"comment","retrieve"),entity_retrieve("comment",a,b)}catch(c){console.log("comment_retrieve - "+c)}}function comment_update(a,b){try{services_resource_defaults(b,"comment","update"),entity_update("comment",null,a,b)}catch(c){console.log("comment_update - "+c)}}function comment_delete(a,b){try{services_resource_defaults(b,"comment","delete"),entity_delete("comment",a,b)}catch(c){console.log("comment_delete - "+c)}}function comment_index(a,b){try{services_resource_defaults(b,"comment","index"),entity_index("comment",a,b)}catch(c){console.log("comment_index - "+c)}}function entity_create(a,b,c,d){try{var e=a+".json";in_array(a,services_entity_types())&&(e="entity_"+e),jDrupal.services.call({method:"POST",async:d.async,path:e,service:d.service,resource:d.resource,entity_type:a,bundle:b,data:JSON.stringify(c),success:function(a){try{d.success&&d.success(a)}catch(b){console.log("entity_create - success - "+b)}},error:function(a,b,c){try{d.error&&d.error(a,b,c)}catch(e){console.log("entity_create - error - "+e)}}})}catch(f){console.log("entity_create - "+f)}}function entity_retrieve(a,b,c){try{var d=a+"/"+b+".json";in_array(a,services_entity_types())&&(d="entity_"+d),jDrupal.services.call({method:"GET",path:d,service:c.service,resource:c.resource,entity_type:a,entity_id:b,success:function(a){try{c.success&&c.success(a)}catch(b){console.log("entity_retrieve - success - "+b)}},error:function(a,b,d){try{c.error&&c.error(a,b,d)}catch(e){console.log("entity_retrieve - error - "+e)}}})}catch(e){console.log("entity_retrieve - "+e)}}function entity_update(a,b,c,d){try{var e=entity_primary_key(a),f=a+"/"+c[e]+".json";in_array(a,services_entity_types())?(f="entity_"+f,data=c):data=_entity_wrap(a,c),jDrupal.services.call({method:"PUT",path:f,service:d.service,resource:d.resource,entity_type:a,entity_id:c[entity_primary_key(a)],bundle:b,data:JSON.stringify(data),success:function(b){try{_entity_local_storage_delete(a,c[e]),d.success&&d.success(b)}catch(f){console.log("entity_update - success - "+f)}},error:function(a,b,c){try{d.error&&d.error(a,b,c)}catch(e){console.log("entity_update - error - "+e)}}})}catch(g){console.log("entity_update - "+g)}}function entity_delete(a,b,c){try{var d=a+"/"+b+".json";in_array(a,services_entity_types())&&(d="entity_"+d),jDrupal.services.call({method:"DELETE",path:d,service:c.service,resource:c.resource,entity_type:a,entity_id:b,success:function(d){try{_entity_local_storage_delete(a,b),c.success&&c.success(d)}catch(e){console.log("entity_delete - success - "+e)}},error:function(a,b,d){try{c.error&&c.error(a,b,d)}catch(e){console.log("entity_delete - error - "+e)}}})}catch(e){console.log("entity_delete - "+e)}}function entity_index(a,b,c){try{var d;"object"==typeof b?d=entity_index_build_query_string(b):"string"==typeof b&&(d=b),d=d?"&"+d:"";var e=a+".json"+d;in_array(a,services_entity_types())&&(e="entity_"+e);var f=entity_caching_enabled(a);if(f){var g=_entity_index_local_storage_load(a,e,{});if(g&&c.success)return void c.success(g)}jDrupal.services.call({method:"GET",path:e,service:c.service,resource:c.resource,entity_type:a,query:b,success:function(d){try{if(c.success){if(f&&b.options&&b.options.entity_load){for(var g=0;g<d.length;g++){var h=d[g];_entity_set_expiration_time(h),_entity_local_storage_save(a,d[g][entity_primary_key(a)],h)}_entity_index_local_storage_save(a,e,d)}c.success(d)}}catch(i){console.log("entity_index - success - "+i)}},error:function(a,b,d){try{c.error&&c.error(a,b,d)}catch(e){console.log("entity_index - error - "+e)}}})}catch(h){console.log("entity_index - "+h)}}function entity_index_build_query_string(a){try{var b="";if(!a)return b;if(a.fields){for(var c="",d=0;d<a.fields.length;d++)c+=encodeURIComponent(a.fields[d])+",";""!=c&&(c="fields="+c.substring(0,c.length-1),b+=c+"&")}if(a.parameters){var e="";for(var f in a.parameters)if(a.parameters.hasOwnProperty(f)){var g=encodeURIComponent(f),h=encodeURIComponent(a.parameters[f]);e+="parameters["+g+"]="+h+"&"}""!=e&&(e=e.substring(0,e.length-1),b+=e+"&")}if(a.parameters_op){var i="";for(var j in a.parameters_op)if(a.parameters_op.hasOwnProperty(j)){var g=encodeURIComponent(j),h=encodeURIComponent(a.parameters_op[j]);i+="parameters_op["+g+"]="+h+"&",i+="options[parameters_op]["+g+"]="+h+"&"}""!=i&&(i=i.substring(0,i.length-1),b+=i+"&")}if(a.orderby){var k="";for(var l in a.orderby)if(a.orderby.hasOwnProperty(l)){var g=encodeURIComponent(l),h=encodeURIComponent(a.orderby[l]);k+="orderby["+g+"]="+h+"&",k+="options[orderby]["+g+"]="+h+"&"}""!=k&&(k=k.substring(0,k.length-1),b+=k+"&")}if(a.options){var m="";for(var n in a.options)if(a.options.hasOwnProperty(n)){var o=a.options[n];if("object"==typeof o){for(var l in o)if(o.hasOwnProperty(l)){var g=encodeURIComponent(l),h=encodeURIComponent(o[l]);m+="options["+n+"]["+g+"]="+h+"&"}}else{var h=encodeURIComponent(o);m+="options["+n+"]="+h+"&"}}""!=m&&(m=m.substring(0,m.length-1),b+=m+"&")}if("undefined"!=typeof a.page&&(b+="page="+encodeURIComponent(a.page)+"&"),"undefined"!=typeof a.page_size){var p="WARNING query.page_size is deprecated, use query.pagesize instead!";console.log(p),b+="pagesize="+encodeURIComponent(a.page_size)+"&"}else"undefined"!=typeof a.pagesize&&(b+="pagesize="+encodeURIComponent(a.pagesize)+"&");return b.substring(0,b.length-1)}catch(q){console.log("entity_index_build_query_string - "+q)}}function _entity_wrap(a,b){try{var c={};return"comment"==a||"taxonomy_term"==a||"taxonomy_vocabulary"==a||"user"==a||-1!=a.indexOf("commerce")?c=b:c[a]=b,c}catch(d){console.log("_entity_wrap - "+d)}}function file_create(a,b){try{services_resource_defaults(b,"file","create"),entity_create("file",null,a,b)}catch(c){console.log("file_create - "+c)}}function file_retrieve(a,b){try{services_resource_defaults(b,"file","retrieve"),entity_retrieve("file",a,b)}catch(c){console.log("file_retrieve - "+c)}}function file_delete(a,b){try{services_resource_defaults(b,"file","delete"),entity_delete("file",a,b)}catch(c){console.log("file_delete - "+c)}}function node_create(a,b){try{services_resource_defaults(b,"node","create"),entity_create("node",a.type,a,b)}catch(c){console.log("node_create - "+c)}}function node_retrieve(a,b){try{services_resource_defaults(b,"node","retrieve"),entity_retrieve("node",a,b)}catch(c){console.log("node_retrieve - "+c)}}function node_update(a,b){try{services_resource_defaults(b,"node","update"),entity_update("node",a.type,a,b)}catch(c){console.log("node_update - "+c)}}function node_delete(a,b){try{services_resource_defaults(b,"node","delete"),entity_delete("node",a,b)}catch(c){console.log("node_delete - "+c)}}function node_index(a,b){try{services_resource_defaults(b,"node","index"),entity_index("node",a,b)}catch(c){console.log("node_index - "+c)}}function system_connect(a){try{var b={service:"system",resource:"connect",method:"POST",path:"system/connect.json",success:function(b){try{jDrupal.user=b.user,a.success&&a.success(b)}catch(c){console.log(c.stack),console.log("system_connect - success - "+c)}},error:function(b,c,d){try{a.error&&a.error(b,c,d)}catch(e){console.log("system_connect - error - "+e)}}};jDrupal.csrf_token?(a.debug&&console.log("Token already available."),jDrupal.services.call(b)):services_get_csrf_token({success:function(c){try{a.debug&&console.log("Grabbed new token."),jDrupal.csrf_token=!0,jDrupal.services.call(b)}catch(d){console.log("system_connect - services_csrf_token - success - "+message)}},error:function(b,c,d){try{a.error&&a.error(b,c,d)}catch(e){console.log("system_connect - services_csrf_token - error - "+d)}}})}catch(c){console.log("system_connect - "+c)}}function taxonomy_term_create(a,b){try{services_resource_defaults(b,"taxonomy_term","create"),entity_create("taxonomy_term",null,a,b)}catch(c){console.log("taxonomy_term_create - "+c)}}function taxonomy_term_retrieve(a,b){try{services_resource_defaults(b,"taxonomy_term","retrieve"),entity_retrieve("taxonomy_term",a,b)}catch(c){console.log("taxonomy_term_retrieve - "+c)}}function taxonomy_term_update(a,b){try{services_resource_defaults(b,"taxonomy_term","update"),entity_update("taxonomy_term",null,a,b)}catch(c){console.log("taxonomy_term_update - "+c)}}function taxonomy_term_delete(a,b){try{services_resource_defaults(b,"taxonomy_term","delete"),entity_delete("taxonomy_term",a,b)}catch(c){console.log("taxonomy_term_delete - "+c)}}function taxonomy_term_index(a,b){try{services_resource_defaults(b,"taxonomy_term","index"),entity_index("taxonomy_term",a,b)}catch(c){console.log("taxonomy_term_index - "+c)}}function taxonomy_vocabulary_create(a,b){try{!a.machine_name&&a.name&&(a.machine_name=a.name.toLowerCase().replace(" ","_")),services_resource_defaults(b,"taxonomy_vocabulary","create"),entity_create("taxonomy_vocabulary",null,a,b)}catch(c){console.log("taxonomy_vocabulary_create - "+c)}}function taxonomy_vocabulary_retrieve(a,b){try{services_resource_defaults(b,"taxonomy_vocabulary","retrieve"),entity_retrieve("taxonomy_vocabulary",a,b)}catch(c){console.log("taxonomy_vocabulary_retrieve - "+c)}}function taxonomy_vocabulary_update(a,b){try{if(!a.machine_name||""==a.machine_name){var c="taxonomy_vocabulary_update - missing machine_name";return console.log(c),void(b.error&&b.error(null,406,c))}services_resource_defaults(b,"taxonomy_vocabulary","update"),entity_update("taxonomy_vocabulary",null,a,b)}catch(d){console.log("taxonomy_vocabulary_update - "+d)}}function taxonomy_vocabulary_delete(a,b){try{services_resource_defaults(b,"taxonomy_vocabulary","delete"),entity_delete("taxonomy_vocabulary",a,b)}catch(c){console.log("taxonomy_vocabulary_delete - "+c)}}function taxonomy_vocabulary_index(a,b){try{services_resource_defaults(b,"taxonomy_vocabulary","index"),entity_index("taxonomy_vocabulary",a,b)}catch(c){console.log("taxonomy_vocabulary_index - "+c)}}function taxonomy_get_tree(a,b,c,d,e){try{var b=arguments[1]?arguments[1]:0,c=arguments[2]?arguments[2]:null,d=arguments[3]?arguments[3]:!1;e.method="POST",e.path="taxonomy_vocabulary/getTree.json",e.service="taxonomy_vocabulary",e.resource="get_tree",e.data=JSON.stringify({vid:a,parent:b,max_depth:c,load_entities:d}),jDrupal.services.call(e)}catch(f){console.log("taxonomy_get_tree - "+f)}}function user_create(a,b){try{services_resource_defaults(b,"user","create"),entity_create("user",null,a,b)}catch(c){console.log("user_create - "+c)}}function user_retrieve(a,b){try{services_resource_defaults(b,"user","retrieve"),entity_retrieve("user",a,b)}catch(c){console.log("user_retrieve - "+c)}}function user_update(a,b){try{var c="create";a.uid&&(c="update"),services_resource_defaults(b,"user",c),entity_update("user",null,a,b)}catch(d){console.log("user_update - "+d)}}function user_delete(a,b){try{services_resource_defaults(b,"user","create"),entity_delete("user",a,b)}catch(c){console.log("user_delete - "+c)}}function user_index(a,b){try{services_resource_defaults(b,"user","create"),entity_index("user",a,b)}catch(c){console.log("user_index - "+c)}}function user_register(a,b){try{jDrupal.services.call({service:"user",resource:"register",method:"POST",path:"user/register.json",data:JSON.stringify(a),success:function(a){try{b.success&&b.success(a)}catch(c){console.log("user_register - success - "+c)}},error:function(a,c,d){try{b.error&&b.error(a,c,d)}catch(e){console.log("user_register - error - "+e)}}})}catch(c){console.log("user_retrieve - "+c)}}function user_login(a,b,c){try{var d=!0;if(a&&"string"==typeof a||(d=!1,console.log("user_login - invalid name")),b&&"string"==typeof b||(d=!1,console.log("user_login - invalid pass")),!d)return void(c.error&&c.error(null,406,"user_login - bad input"));jDrupal.services.call({service:"user",resource:"login",method:"POST",path:"user/login.json",data:"username="+encodeURIComponent(a)+"&password="+encodeURIComponent(b),success:function(a){try{jDrupal.user=a.user,jDrupal.sessid=null,services_get_csrf_token({success:function(b){try{c.success&&system_connect({success:function(b){try{c.success&&c.success(a)}catch(d){console.log("user_login - system_connect - success - "+d)}},error:function(a,b,d){try{c.error&&c.error(a,b,d)}catch(e){console.log("user_login - system_connect - error - "+e)}}})}catch(d){console.log("user_login - services_get_csrf_token - success - "+d)}},error:function(a,b,d){console.log("user_login - services_get_csrf_token - error - "+d),c.error&&c.error(a,b,d)}})}catch(b){console.log("user_login - success - "+b)}},error:function(a,b,d){try{c.error&&c.error(a,b,d)}catch(e){console.log("user_login - error - "+e)}}})}catch(e){console.log("user_login - "+e);
}}function user_logout(a){try{jDrupal.services.call({service:"user",resource:"logout",method:"POST",path:"user/logout.json",success:function(b){try{jDrupal.user=drupal_user_defaults(),jDrupal.sessid=null,system_connect({success:function(c){try{a.success&&a.success(b)}catch(d){console.log("user_logout - system_connect - success - "+d)}},error:function(b,c,d){try{a.error&&a.error(b,c,d)}catch(e){console.log("user_logout - system_connect - error - "+e)}}})}catch(c){console.log("user_logout - success - "+c)}},error:function(b,c,d){try{a.error&&a.error(b,c,d)}catch(e){console.log("user_logout - error - "+e)}}})}catch(b){console.log("user_login - "+b)}}function user_request_new_password(a,b){try{"undefined"==typeof b.data&&(b.data={}),b.data.name=a,b.data=JSON.stringify(b.data),b.method="POST",b.path="user/request_new_password.json",b.service="user",b.resource="request_new_password",jDrupal.services.call(b)}catch(c){console.log("user_request_new_password - "+c)}}var jDrupal={};if(drupal_init(),!Drupal)var Drupal=jDrupal;var module_invoke_results=null,module_invoke_continue=null;jDrupal.fieldHasItem=function(a,b,c,d){return c||(c=language_default()),"undefined"==typeof d&&(d=0),a[b]&&a[b][c]&&a[b][c].length&&a[b][c][d]},jDrupal.fieldGetItem=function(a,b,c,d){return c||(c=language_default()),"undefined"==typeof d&&(d=0),a[b][c][d]},jDrupal.fieldGetItemCount=function(a,b,c){return c?jDrupal.fieldGetItems(a,b,c).length:jDrupal.fieldGetItems(a,b).length},jDrupal.fieldGetItems=function(a,b,c){return c||(c=language_default()),a[b][c]},jDrupal.fieldSetItem=function(a,b,c,d,e,f){e||(e=language_default()),"undefined"==typeof f&&(f=0),a[b]||(a[b]={}),c?(a[b][e]||(a[b][e]=[]),a[b][e][f]||(a[b][e][f]={}),a[b][e][f][c]=d):a[b][e][f]=d},jDrupal.services={},jDrupal.services.call=function(a){try{if(a.debug=!1,!services_ready()){var b="Set the site_path and endpoint on jDrupal.settings!";return void a.error(null,null,b)}module_invoke_all("services_preprocess",a);var c=new XMLHttpRequest,d=jDrupal.settings.site_path+jDrupal.settings.base_path+"?q=";"undefined"==typeof a.endpoint?d+=jDrupal.settings.endpoint+"/":""!=a.endpoint&&(d+=a.endpoint+"/"),d+=a.path;var e=a.method.toUpperCase();jDrupal.settings.debug&&console.log(e+": "+d),c.onreadystatechange=function(){4==c.readyState&&0==c.status&&a.error&&a.error(c,0,"xhr network status problem")},c.onload=function(b){try{if(4==c.readyState){var f=c.status+" - "+c.statusText;if(200==c.status){jDrupal.settings.debug&&console.log("200 - OK");var g=null,h=c.getResponseHeader("Content-Type");g=-1!=h.indexOf("application/json")?JSON.parse(c.responseText):c.responseText,module_invoke_all("services_request_pre_postprocess_alter",a,g),a.success(g),module_invoke_all("services_request_postprocess_alter",a,g),module_invoke_all("services_postprocess",a,g)}else{if(console.log(e+": "+d+" - "+f),jDrupal.settings.debug&&(in_array(c.status,[403,503])||console.log(c.responseText),console.log(c.getAllResponseHeaders())),"undefined"!=typeof a.error){var i=c.responseText||"";i&&""!=i||(i=f),a.error(c,c.status,i)}module_invoke_all("services_postprocess",a,c)}}else console.log("jDrupal.services.call - request.readyState = "+c.readyState)}catch(j){jDrupal.settings.debug&&(console.log(e+": "+d+" - "+c.statusText),console.log(c.responseText),console.log(c.getAllResponseHeaders())),console.log("jDrupal.services.call - onload - "+j)}},services_get_csrf_token({debug:a.debug,success:function(b){try{var f=!0;"undefined"!=typeof a.async&&a.async===!1&&(f=!1),c.open(e,d,f);var g=null;"POST"==e?(g="application/json","user"==a.service&&"login"==a.resource&&(g="application/x-www-form-urlencoded")):"PUT"==e&&(g="application/json"),a.contentType&&(g=a.contentType),g&&c.setRequestHeader("Content-type",g),b&&c.setRequestHeader("X-CSRF-Token",b),a.timeout&&(c.timeout=a.timeout,a.ontimeout&&(c.ontimeout=a.ontimeout));var h="undefined"!=typeof a.data;if("POST"!=e||h||(a.data=JSON.stringify(""),h=!0),h){if(jDrupal.settings.debug){var i=!0;("user"==a.service&&in_array(a.resource,["login","create","update"])||"file"==a.service&&"create"==a.resource)&&(i=!1),i&&("object"==typeof a.data?console.log(JSON.stringify(a.data)):console.log(a.data))}c.send(a.data)}else c.send(null)}catch(j){console.log("jDrupal.services.call - services_get_csrf_token - success - "+j)}},error:function(b,c,d){try{a.error&&a.error(b,c,d)}catch(e){console.log("jDrupal.services.call - services_get_csrf_token - error - "+e)}}})}catch(b){console.log("jDrupal.services.call - error - "+b)}};