var ENTITY_TECNOCLOUD='tecnocloud'; var ENTITY_CONFIGURATION='configuration'; var ENTITY_CONFIGURATION_COMPANY='configuration_company'; var ENTITY_DEVICES='devices'; var ENTITY_DATA='data'; var ENTITY_DOWNLOAD='download'; var ENTITY_STATISTICS='statistics'; var ENTITY_SEARCH='search'; var ENTITY_TECNOSOFT='admin'; var ENTITY_CERTIFICATES='publiccertificates'; var ENTITY_CREATEUSER='createuser'; //function to initialize the page var init = function(entity) { //showing the home tab on initializing showTab(entity); //adding event listeners to the tabs $('#tabs a').click(function(event) { showTab(event.currentTarget.id); }); } //function to show the tab var showTab = function(entity) { //remove the active class from all the tabs //$('.tab').removeClass("active"); //setting the active class to the selected tab $('#'+entity).addClass("active"); //hiding all the tabs // $('.g-unit').hide(); //showing the selected tab // $('#' + entity + '-tab').show(); //hiding the message block // $('.message').hide(); //hiding the create block // showHideCreate(entity, false); // if(entity!=HOME) // $('#'+entity+'-search-reset').click(); } //function to show/hide create block for an entity in a tab var showHideCreate = function(entity, show) { //checking if the block is show or not if (show) { //hiding the search container $('#' + entity + '-search-ctr').hide(); //hiding the list container $('#' + entity + '-list-ctr').hide(); //showing the create container $('#' + entity + '-create-ctr').show(); } else { //showing the search container $('#' + entity + '-search-ctr').show(); //showing the list container $('#' + entity + '-list-ctr').show(); //hiding the create container $('#' + entity + '-create-ctr').hide(); //checking if the entity is not a home then populating the list of the entity if(entity!=HOME) populateList(entity,null); } } //parameter object definition var param=function(name,value){ this.name=name; this.value=value; } //function to add an entity when user clicks on the add button in UI var add = function(entity) { $('.message').hide(); $('#'+entity+'-reset').click(); //display the create container showHideCreate(entity, true); $("span.readonly input").attr('readonly', false); $("select[id$=order-customer-list] > option").remove(); $("select[id$=order-item-list] > option").remove(); $("select[id$=item-product-list] > option").remove(); //checking the entity to populate the select box if (entity == ENTITY_ITEM) { //populating the product and contact by making an ajax call populateSelectBox('item-product-list', '/product'); } else if (entity == ENTITY_ORDER){ // populating the customer and item select box by making an ajax call populateSelectBox('order-customer-list','/customer'); populateSelectBox('order-item-list','/item'); } } //function to search an entity when user inputs the value in the search box var search = function(entity) { $('.message').hide(); // collecting the field values from the form var formEleList = $('form#'+entity+'-search-form').serializeArray(); //assigning the filter criteria var filterParam=new Array(); for(var i=0;i'+message+'

'); } var formValidate = function(entity){ //var key; //var formEleList = $('form#'+entity+'-create-form').serializeArray(); //key=formEleList[0].value; switch(entity){ case ENTITY_TECNOCLOUD: var user = $('#user').val(); var password = $('#password').val(); if(user == "" || password== ""){ //alert(user + ' ' + password); showMessage('please check the user and the password values in the form', entity); return; } break; case ENTITY_CONFIGURATION: var password = $('newPassword').val(); var password2 = $('newPassword2').val(); if(password!=password2){ showMessage('different password', entity); return; } break; default : break; } //save(entity); $('#'+entity+'-show-message').hide(); } //function to save an entity var save = function(entity) { // creating the data object to be sent to backend var data=new Array(); // collecting the field values from the form var formEleList = $('form#'+entity+'-create-form').serializeArray(); for(var i=0;i option").remove(); ele.append(''); } else ele.val(eval('data.'+ele.attr('name'))); } } showHideCreate(entity, true); $("span.readonly input").attr('readonly', true); } }); } //function called when user clicks on the cancel button var cancel = function(entity) { $('.message').hide(); //hiding the create container in the tab showHideCreate(entity, false); } //function to delete an entity var deleteEntity = function(entity,id,parentid) { var parameter=new Array(); parameter[parameter.length]=new param('id',id); parameter[parameter.length]=new param('parentid', parentid); parameter[parameter.length]=new param('action','DELETE'); //making the ajax call $.ajax({ url : "/"+entity, type : "POST", data:parameter, dataType:"html", success : function(resp) { showHideCreate(entity,false); if (resp!=''){ showMessage(resp, entity); } }, error : function(resp){ showMessage(resp, entity); } }); } // function to get the data by setting url, filter, success function and error function var getData=function(url,filterData,successFn,errorFn){ // making the ajax call $.ajax({ url : url, type : "GET", data:filterData, success : function(resp) { //calling the user defined success function if(successFn) successFn(resp); }, error:function(e){ //calling the user defined error function if(errorFn) errorFn(e); } }); } //function to populate the select box which takes input as id of the selectbox element and url to get the data var populateSelectBox = function(id, url) { //specifying the success function. When the ajax response is successful then the following function will be called var successFn=function(resp){ //getting the select box element var selectBox=$('#'+id); //setting the content inside as empty selectBox.innerHTML = ''; //getting the data from the response object var data=resp.data; //appending the first option as select to the select box selectBox.append(''); //adding all other values for (var i=0;i'+data[i].name+''); } } //calling the getData function with the success function getData(url,null,successFn,null); } //function to populate the list of an entity var populateList=function(entity, filter){ //specifying the success function. When the ajax response is successful then the following function will be called var successFn=function(resp){ var data=''; if(resp){ //getting the data from the response object data=resp.data; } //creating the html content var htm=''; if(data.length > 0){ for (var i=0;i'+data[i].description+''; break; case ENTITY_ITEM: htm+=''+data[i].name+''+data[i].price+''+data[i].product+''; break; case ENTITY_ORDER: htm+=''+data[i].name+''+data[i].itemName+''+data[i].customerName+''+data[i].shipTo+','+data[i].city+','+data[i].state+'-'+data[i].zip+''+data[i].quantity+''+data[i].price+''; break; case ENTITY_CUSTOMER: htm+=''+data[i].name+''+data[i].firstName+''+data[i].lastName+''+data[i].address+','+data[i].city+','+data[i].state+'-'+data[i].zip+''+data[i].phone+''+data[i].eMail+''; break; default: htm+=""; } if(entity != ENTITY_ORDER) htm+='Delete | Edit'; else htm+='Delete'; } } else{ //condition to show message when data is not available var thElesLength=$('#'+entity+'-list-ctr table thead th').length; htm+='No items found'; } $('#'+entity+'-list-tbody').html(htm); } getData("/"+entity,filter,successFn,null); }