This is a rebranded clone of MetamorFit.org. It's a sandbox for me to play in, a place to store snippets, this is not a real blog. Comments are disabled, try stack overflow if you feel a need to comment.

7. August 2014 14:52
by james
0 Comments

Angular JS in SharePoint 2010 Content Editor against simple list called TestQuestions

7. August 2014 14:52 by james | 0 Comments

 

 

<script src='//ajax.googleapis.com/ajax/libs/angularjs/1.2.21/angular.min.js'></script>
<script>
    function QuestionnaireCtrl($scope) {
        $scope.questions = [
            { text: 'How would you like your eggs done?', answer: "" },
            { text: 'What kind of bread would you like?', answer: "" },
            { text: 'What kind of drink would you like?', answer: "" }
        ];
 
        $scope.addAnswers = function ($event) {

            $event.preventDefault();

            var clientContext = new SP.ClientContext.get_current();
            var web = clientContext.get_web();
			clientContext.load(web);
            var list = web.get_lists().getByTitle('TestQuestions');
			clientContext.load(list);
			
					
 
			angular.forEach($scope.questions, function (question, i) {
				// create the ListItemInformational object
				var listItemInfo = new SP.ListItemCreationInformation();
				// add the item to the list
				var listItem = list.addItem(listItemInfo);
				// Assign Values for fields
				listItem.set_item('Question', question.text);
				listItem.set_item('Answer', question.answer);
				listItem.set_item('Title', 'Question ' + (++i));
	 
				listItem.update();
			});

 
            clientContext.executeQueryAsync(
                Function.createDelegate(this, onQuerySucceeded),
                Function.createDelegate(this, onQueryFailed)
            );
 
        };
 
        onQuerySucceeded = function () {
            alert('Thank you, have a nice day.');
            var questions = $scope.questions;
			angular.forEach(questions, function (question) {
				question.answer = "";
			});
            $scope.$apply();
        }
 
        onQueryFailed = function (sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
        }
    }
</script>
<h1>Testing Angular.js</h1>
 
<div ng-app>   
    <div ng-controller="QuestionnaireCtrl">     
        <ol>
            <li ng-repeat="question in questions">
                <span>{{question.text}}</span>
                <br />
                <input type="text" ng-model="question.answer"/>
            </li>
        </ol>           
        <input type="submit" value="Submit" ng-click="addAnswers($event)"/>
    </div>
</div>

1. August 2014 14:53
by james
0 Comments

Script I want to save

1. August 2014 14:53 by james | 0 Comments

 

 

<script type="text/javascript" id="onetidPageTitleAreaFrameScript">
	var currentUserIsCorpComm = false;
	var templatevalue;
	if (document.getElementById("onetidPageTitleAreaFrame") != null)
	{
		document.getElementById("onetidPageTitleAreaFrame").className="ms-areaseparator";
	}
	
	jQuery(document).ready(
		function() {ExecuteOrDelayUntilScriptLoaded(SPDocumentReady, "sp.js");
	});

	
	var fieldprefix = '#ctl00_m_g_9ce3f532_0a90_4d75_acb0_8e2b7b8caf25_';
	var sitetitlefieldid = fieldprefix + 'ff21_ctl00_ctl00_TextField';
	var siterequestedurlfieldid = fieldprefix + 'ff121_ctl00_ctl00_TextField';
	var siterequestedurllabelid = '#lblh3SiteRequestedURL';
	var divcoordapprovalstatusfieldid = fieldprefix + 'ff171_ctl00_DropDownChoice';
	var corpcommapprovalstatusfieldid = fieldprefix + 'ff141_ctl00_DropDownChoice';
	var divcoordapproversfieldid = fieldprefix + 'ff151_ctl00_ctl00_TextField';
	var corpcommapproversfieldid = fieldprefix + 'ff131_ctl00_ctl00_TextField';
	var sitetemplatefieldid = fieldprefix + 'ff181_ctl00_Lookup';


	function SPDocumentReady() {
		try
		{
			this.currentcontext = new SP.ClientContext.get_current();
			this.web = this.currentcontext.get_web();
			this.currentcontext.load(this.web);
	
			this.user = this.web.get_currentUser();
			this.user.retrieve();
			this.currentcontext.load(this.user);
			this.currentcontext.executeQueryAsync(Function.createDelegate(this, this.onSuccess), Function.createDelegate(this, this.onFail));
		}
		catch(err) {
			alert(err.message);
		}
	}

	function onSuccess() {
		var loginnametolower = this.user.get_loginName().toLowerCase();

		var divcoordapprovers = jQuery(divcoordapproversfieldid).val().toLowerCase();
		var corpcommapprovers = jQuery(corpcommapproversfieldid).val().toLowerCase();

		
		if(divcoordapprovers.indexOf(loginnametolower) > -1) {   
			jQuery('#tblrowDivCoordApprovalStatus').show();
			
			jQuery(divcoordapprovalstatusfieldid).change(function() {
				if(jQuery(divcoordapprovalstatusfieldid).val() == 'Rejected')
	        	{
	        		jQuery(siterequestedurlfieldid).val('DECLINED');
	        	}
	        	else
	        	{
	        		if(jQuery(siterequestedurlfieldid).val() == 'DECLINED')
	        		{
	        			jQuery(siterequestedurlfieldid).val('');
	        		}
	        	}        
	        });

		}
		
		if(corpcommapprovers.indexOf(loginnametolower) > -1) { 
			currentUserIsCorpComm = true;  
			jQuery('#tblrowCorpCommApprovalStatus').show();
			jQuery('#tblrowSiteRequestedURL').show();
			jQuery('#tblrowTypeofSite').show();
			jQuery('#tblrowDivCoordApprovalStatus').show();
			
			
			 jQuery(corpcommapprovalstatusfieldid).change(function() {
				if(jQuery(corpcommapprovalstatusfieldid).val() == 'Rejected')
	        	{
	        		jQuery(siterequestedurlfieldid).val('DECLINED');
	        	}
	        	else
	        	{
	        		if(jQuery(siterequestedurlfieldid).val() == 'DECLINED')
	        		{
	        			jQuery(siterequestedurlfieldid).val('');
	        		}
	        	}        
	        });

			
   		
    		var uniquename =  jQuery(sitetitlefieldid).val().replace(/\s+/g, '');
 	        jQuery(sitetemplatefieldid).change(function() {
 	        
 	        	templatevalue = jQuery(sitetemplatefieldid).val();
 	        	switch(templatevalue) {
 	        		case '1':
 	        		case '5':
 	        		case '6':
 	        			jQuery(siterequestedurlfieldid).val('https://' + window.location.hostname + '/sitedev/' + uniquename);
 	        		break;
 	        		
 	        		case '3':
 	        			jQuery(siterequestedurlfieldid).val('https://' + window.location.hostname + '/sitedev/forums/' + uniquename);
 	        		break;

 	        		case '4':
 	        			jQuery(siterequestedurlfieldid).val('https://' + window.location.hostname + '/sitedev/geo/' + uniquename);
 	        		break;

 	        		case '2':
 	        			jQuery(siterequestedurlfieldid).val('https://' + window.location.hostname + '/sitedev/operatinggroups/' + uniquename);
 	        		break;

 	        		default:
 	        			jQuery(siterequestedurlfieldid).val('');
 	        		break;
 	        	
 	        	}
        
	        });
	        

		}


	}
	
	function onFail(sender, args) {
		alert(args.get_message());	
	}
	
	function PreSaveAction() { 
		if(currentUserIsCorpComm) 
		{
			if(jQuery(corpcommapprovalstatusfieldid).val() == 'Approved')
			{
				if((templatevalue != '0') && (isValidhttpUrl(jQuery(siterequestedurlfieldid).val()))) {
					jQuery(divcoordapprovalstatusfieldid).val('Approved');
					return true;
				}
				else
				{
					alert('Either Type of Site was not selected or a valid Site URL has not been set.\n\nPlease verify that all required fields have been set.');
					return false;
				}
			}
		}
	}
	
	function isValidhttpUrl(s) {
 		var regexp = /(http|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?/;
 		return regexp.test(s);
	}

	
 </script>

26. July 2014 21:18
by james
0 Comments

Hello Angular World

26. July 2014 21:18 by james | 0 Comments

Hello Angular World:

 

var MainController = function($scope, $http) {
	var onUserComplete = function(reponse) {
		$scope.user = reponse.data;
	};
	
	var onError = function(reason) {
		$scope.error = "Could not fetch the user";
	};
	
	$http.get("https://api.github.com/users/robconery")
		.then(onUserComplete, onError);
		
	$scope.message = "Hello, Angular World!";
};