Created
June 5, 2013 11:53
-
-
Save maowug/5713371 to your computer and use it in GitHub Desktop.
updateDescriptors with $watch (better do it with back-end)
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
// $scope.$watch('settingsTogo.advancedSettings.length', function(){ | |
$scope.updateDescriptors = function(){ | |
var ace=$scope.settingsTogo.advancedSettings; | |
var raw_odList=ace.slice(ace.lastIndexOf('>')+1).split('[\'');//console.log(raw_odList); | |
var orDescriptorsTemp=[]; | |
var orDscMsgsTemp=[]; | |
_.each(raw_odList,function(rod, idx, list){ | |
// each rod if no ']' return else good push it to orDescriptors | |
if(rod.length<5||rod.indexOf(']')==-1) return; | |
//eval od to array=['name',[1,2,3]] | |
var od2='[\''+rod.replace('(','['); | |
var od=eval(od2.replace(')',']'));//console.log(od); | |
// if od format is correct | |
if(_.isString(od[0])&& _.isArray(od[1])) { | |
var idxOfName=_.indexOf($scope.attNameList,od[0]); | |
if(idxOfName!=-1){ //console.log(od[1]); | |
var attValueList=_.map(od[1],function(k){ | |
//todo: if no "k<=", undefined[0] would be an error, instead of undefined | |
if(_.isNumber(k)){ | |
if(k>=$scope.AT[idxOfName].length) { | |
orDscMsgsTemp.push(od[1]+'Invalid '); | |
return; | |
} else { | |
return $scope.AT[idxOfName][k][0]; | |
} | |
} | |
if(_.isString(k)) { | |
var tempATC= _.map($scope.AT[idxOfName],function(rC){return rC[0];}); | |
return tempATC[_.indexOf(tempATC,k)]; | |
} else{ // not Number not String | |
orDscMsgsTemp.push(od[1]+'Invalid '); | |
} | |
}); | |
// value from isString could be undefined | |
if(_.all(attValueList)) { | |
orDescriptorsTemp.push([od[0],attValueList]) | |
} else{// some k mismatch | |
orDscMsgsTemp.push(od[1]+'Invalid '); | |
} | |
} else {//idxOfName==-1, AttributeName mismatch | |
orDscMsgsTemp.push(od[0]+' is not a valid attribute name.'); | |
} | |
} else { //od format is not correct | |
orDscMsgsTemp.push('['+od+'] is Not good enough.') | |
} | |
}); | |
//eof: each rod | |
$scope.settingsTogo.orDescriptors=orDescriptorsTemp; | |
$scope.settingsTogo.orDscMsgs=orDscMsgsTemp; | |
//console.log(orDescriptorsTemp); | |
//console.log(orDscMsgsTemp); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment