Last active
May 31, 2018 07:37
-
-
Save tabebqena/342d5fbd7a7f79a39383d0638d0c27ec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function clearDropBtn(id){ | |
| try{ | |
| document.getElementById(id).options.length = 0; | |
| }catch(err){ | |
| console.error(err.name, err.message) | |
| } | |
| } | |
| function clearDropBtnExceptFirst(id){ | |
| try{ | |
| var sel = document.getElementById(id) | |
| var opt = sel.options[0]; | |
| sel.options.length = 1; | |
| }catch(err){ | |
| console.error(err.name, err.message) | |
| } | |
| } | |
| function getOptionIndices(dbtnCl){ | |
| try{ | |
| console.info("function: getOptionIndices.\nArguments: "+dbtnCl) | |
| var array = []; | |
| var ele = document.getElementsByClassName(dbtnCl); | |
| for (i in ele ){ | |
| array.push( ele[i].selectedIndex); | |
| } | |
| return array; | |
| } | |
| catch(err) { | |
| console.error(err.name , err.message); | |
| } | |
| } | |
| function getOptionIndex(dbtnID){ | |
| try{ | |
| console.info("function: getOptionIndex.\nArguments: "+dbtnID) | |
| var ele = document.getElementById(dbtnID); | |
| return ele.selectedIndex; | |
| } | |
| catch(err) { | |
| console.error(err.name , err.message); | |
| } | |
| } | |
| function getDropBtn(id="", cl=""){ | |
| try{ | |
| console.info("function: getDropBtm.\nArguments: "+id + " " + cl) | |
| if (id != ""){ | |
| var e = document.getElementById(id); | |
| return e.options[e.selectedIndex].text; | |
| }else if (cl !=""){ | |
| var array = []; | |
| var e = document.getElementByClassName(cl); | |
| for (var i=0 ; i< e.length ; i++){ | |
| array.push( e.options[e.selectedIndex].text ); | |
| }; | |
| return array ; | |
| } ; | |
| } | |
| catch(err) { | |
| console.error(err.name , err.message); | |
| } | |
| } | |
| function getHiddenValue(id){ | |
| try{ | |
| return document.getElementById(id).value ; | |
| }catch(err){ | |
| console.error(err.name, err.message) | |
| } | |
| } | |
| function setDropBtnByVal(params){ | |
| console.info("function: setDropBtnByVal.\nArguments: ", params) | |
| try{ | |
| var id = params.id; | |
| var val =params.val; | |
| var opts = document.getElementById(id).options | |
| var options =[]; | |
| for (var x =0; x < opts.length; x++){ | |
| options.push(opts[x].text) | |
| } | |
| var index = options.indexOf(val); | |
| if (index > -1){ | |
| setDropBtn({id:id, index:index}) | |
| }else {console.log(options, val)} | |
| }catch(err) { | |
| console.error(err.name , err.message); | |
| } | |
| } | |
| function setDropBtn(userObject ){ | |
| try{ | |
| console.info("function: setDropBtn.\nArguments: ") | |
| var id = userObject.id; | |
| var index = userObject.index; | |
| var value = userObject.value; | |
| var btn = document.getElementById(id); | |
| if (index !== ""){ | |
| btn.selectedIndex = index | |
| }else {btn.innerHTML=value} | |
| } | |
| catch(err) { | |
| console.error(err.name , err.message); | |
| } | |
| } | |
| function fillSelByArray(dist, userObject){ | |
| try{ | |
| console.info("function: fillSelByArray.\nArguments: " , dist, userObject) | |
| // userObject = {spin:true , prepare:true, selId:"", key:"mainSpin", cga:{},sort:sorterr, } | |
| if (userObject.hasOwnProperty("spin") && userObject.spin == true ){ | |
| hideSpinnerShowElement(); | |
| } | |
| if (userObject.hasOwnProperty("cga") ){ | |
| var x=0; | |
| var cga = userObject.cga; | |
| var cgaK = Object.keys(cga); // keys=["registeredSuppliers"] | |
| for (x=0 ; x<cgaK.length; x++){ | |
| var key = cgaK[x] //"registeredSuppliers" | |
| var val = cga[key] // firstargumen | |
| if (val == "firstargument"){val = dist} | |
| CGA[key] = val; | |
| } | |
| } | |
| if (userObject.check != CGA["mode"]){console.log("Cancelled, The mode changed", userObject.check, CGA["mode"]); return} | |
| var sel = document.getElementById( userObject.selId ) ; | |
| var keys = Object.keys(dist); | |
| for (var x=0; x< keys.length; x++ ) { | |
| //var key = | |
| var val = dist[x][0] ; | |
| // console.log(val) | |
| if (val == "" ){ | |
| continue | |
| } | |
| var option = document.createElement("option"); | |
| option.innerHTML = String(val); | |
| sel.append(option); | |
| } | |
| }catch(err) { | |
| console.error(err.name , err.message, err); | |
| } | |
| }; | |
| function fillSelOptions(dist, userObject){ // keys=true, spin=true , prepare=false, cga={}, selId, msg, key | |
| try{ | |
| console.info("function: fillSelOptions.\nArguments: " , dist, userObject) | |
| // userObject = {keys:true, spin:true , prepare:true, selId:"", key:"mainSpin", cga:{},sort:sorterr, call,params} | |
| if (userObject.hasOwnProperty("spin") && userObject.spin == true ){ | |
| hideSpinnerShowElement() | |
| } | |
| if (userObject.hasOwnProperty("prepare") && userObject.prepare == true){ | |
| var mode = CGA["mode"]; | |
| if (mode == "recievedRequests" && userObject.selId == "otherMan_input"){mode = "otherMen"}else if(mode=="sales" && userObject.selId == "ourMan_input"){mode="OurMen"}; | |
| var dist = prepareArray(mode, dist ); | |
| } | |
| if (userObject.hasOwnProperty("sort") && userObject.sort != null){ | |
| } | |
| if (userObject.hasOwnProperty("cga") && userObject.cga != {}){ | |
| var x=0; | |
| var cga = userObject.cga; | |
| var cgaK = Object.keys(cga); // keys=["registeredSuppliers"] | |
| if (userObject.hasOwnProperty("sort") && userObject.sort != null){ | |
| cgaK = Object.keys(cga).sort( userObject.sort ); | |
| } | |
| for (x ; x<cgaK.length; x++){ | |
| var key = cgaK[x] //"registeredSuppliers" | |
| var val = cga[key] // firstargumen | |
| if (val == "firstargument"){val = dist} | |
| CGA[key] = val; | |
| } | |
| } | |
| if (typeof(userObject.selId) == 'string' && userObject.check == CGA["mode"]){ | |
| var sel = document.getElementById( userObject.selId ) ; | |
| var myOptions = dist ; | |
| if (userObject.hasOwnProperty("sorter") ){ | |
| var keys = Object.keys(myOptions).sort( userObject.sorter ); | |
| }else { | |
| var keys = Object.keys(myOptions) | |
| } | |
| for (var x=0; x< keys.length; x++ ) { | |
| var key = keys[x] | |
| var val = myOptions[key] ; | |
| if (val == "" ){ | |
| continue} | |
| var option = document.createElement("option"); | |
| option.innerHTML = String(val); | |
| if ( userObject.keys == true){ | |
| option.value = key; | |
| } | |
| sel.append(option); | |
| } | |
| }else if (typeof(userObject.selId) === "object"){ | |
| }else{return} | |
| if (userObject.call != undefined){ | |
| if (userObject.params == null){ | |
| userObject.call() | |
| }else{ | |
| userObject.call(userObject.params) | |
| } | |
| } | |
| }catch(err) { | |
| console.error(err.name , err.message, err); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment