Augmenting controller with events - angularjs

I am currently writing a single page web application for a parties producing company.
My goal is to create an "Office like" application that will allow the users to open a new "party document " and edit it.
Each document will have a lot of "content pages" (like food , utilities, attractions ,suppliers etc...) and in each page there will be many fields.
Each field will have it own restrictions that should occure when it is being added , removed or edited.
I wanted to make a base JavaScript object that all other fields object will inherit from . It looks like this :
`
function RootComponent(name,value){
this.name = name;
this.value = null;
// Logic restrictions methods
this.onChange = null;
this.afterChange = null;
this.onCheck = null;
this.onDelete = null;
this.afterDelete = null;
this.onAdd = null;
// Ensure we got value
if (value !== undefined){
this.value = value;
}
}
`
My question is how should I augment the events of "OnChange" and such with Angular's $watch system.

Related

Migrating jQuery selector to angularjs for third party vendor client help functionality

I'm trying to migrate old jQuery code to angularjs.
The issue that I'm having is that I'm not sure on the best approach.
Bascially, depending on the selector a different type of 'event' needs to be pushed into a array called gt.
The purpose of the jQuery code is to provide detailed info of clients having issues while filling in a form. the gt array is picked up by third party software that helps the clients by asking if they want to chat.
Example of how the array is populated:
$('a').live('click', { element: this }, function (element) {
_clickedElement = this;
var linkUrl = element.currentTarget.hostname + element.currentTarget.pathname;
var querystring = window.location.search
var shortLocationUrl = window.location.href.replace(querystring, "").replace("http://", "").replace("https://", "");
if (element.currentTarget.hostname.length > 0 && element.currentTarget.target != "_blank" && linkUrl != shortLocationUrl) { //click on a link that opens in the current window and points to a page external to this part
_gt.push(['event', { eventName: 'Leave_Page_' + chat.name, name: chat.name, pageName: chat.pageName, locale: _locale, isClient: chat.isClient }]);
_pushLeavePageEvent = false;
}
else if (this.id == backButtonId) { //click "previous"
_gt.push(['event', { eventName: 'Go_Back_' + chat.name, name: chat.name, pageName: chat.pageName, locale: _locale, isClient: chat.isClient }]);
_pushLeavePageEvent = false;
}
return true;
});
So for all the a tags inside my page (or form) the above code needs to be executed.
What would be a good approach to have similar behaviour in Angularjs?
I was thinking of a directive but I'm not sure whether to make this a directive at the level of my form or make a directive that I then use throughout my page?
P.S.: similar behaviour is needed (pushing an event into the gt array) for all the input, textarea and select fields on the page as well as the errors on the page caused by the clients and when a client hovers over a tooltip.

find out duplicate entry while editing the person name information in angular

I can create people information with their b'date using add button. It get displayed top of the page. If i want to edit information, I again click on that information and edit it easily. I need one validation there that i should not choose bday.name(person name) duplicate. e.q. if i already have "peter" person so i can't edit and change any other person name to "peter". so need to avoid duplicate entry in list.
plunker: http://plnkr.co/edit/2UFfaG?p=preview
$scope.newBirthday = function(){
$scope.bdays.push({name:$scope.bdayname, date:$scope.bdaydate});
$scope.bdayname = '';
$scope.bdaydate = '';
};
here is a simple solution using only angular js :
$scope.newBirthday = function(){
var exist=false;
angular.forEach($scope.bdays, function(bday) {
if(bday.name===$scope.bdayname){
exist=true;
bday.date=angular.copy($scope.bdaydate);
}
});
if(!exist){
$scope.bdays.push({name:$scope.bdayname, date:$scope.bdaydate});
}
$scope.bdayname = '';
$scope.bdaydate = '';
};

How do you properly set a custom profile property in DNN?

I'm trying to save a custom property to an existing user profile in DNN 7, but the profile property is not getting set. I must be understanding something incorrectly.
So, how do you properly set a custom profile property in DNN?
UserInfo.Profile.SetProfileProperty("key","value")
// I expect this to return "value", but it's always ""
var value = UserInfo.Profile.GetProfileProperty("key");
// Even if I save it...
ProfileController.UpdateUserProfile(UserInfo);
// It always returns ""
var savedValue = UserInfo.Profile.GetProfileProperty("key");
Note: I also tried InitialiseProfile but that didn't change the behavior.
Here is how I am accessing a propertyvalue from a property in a module base class I have for a client.
public string SomeKey
{
get
{
var ppd = UserInfo.Profile.GetProperty("SomeKey");
if (ppd.PropertyValue == string.Empty)
{
var SomeKeyValue = "blah"
//update the user's profile property
UserInfo.Profile.SetProfileProperty("SomeKey", SomeKeyValue);
//save the user
DotNetNuke.Entities.Users.UserController.UpdateUser(PortalId, UserInfo);
//retrieve again
return SomeKey;
}
string returnValue = ppd.PropertyValue ??
(String.IsNullOrEmpty(ppd.DefaultValue) ? String.Empty : ppd.DefaultValue);
return returnValue;
}
}

How to define a Backbone.Collection to be a property but not an attribute of a Backbone.Model?

Say I have a web application which allows to filter a set of items and say that I'm using backbone.js in the web frontend.
Quite naturally I ended up creating a Filter which extends Backbone.Model and a SearchResultList extending Backbone.Collection. The Filter has some attributes like searchTerm, dataFrom, dateTo... Filter also has a method called applyFilter. Filter.applyFilter should call searchResultList.fetch, thus updating/filtering the search results.
The question is, how to best initialize searchResultList as a property of Filter instead of being an attribute in Backbone terms?
I would not like to create the SearchResultList in Filter.initialize as SearchResultList is not necessarily "owned" by Filter.
For now I ended up passing the searchResultList object as an option to Filter.initialize, but that feels a little bit awkward to me.
I doubt that it is a good idea to let Filter.applyFilter call SearchResultList.fetch. However, there needs to be a method of Filter which when called triggers a new request somehow. (Listening to change events of Filter is not an option either as the user is supposed to change filter options in multiple steps and decides to apply the filter manually via a button click)
I have a Collection for performing searches. Most of my collections extend this Search Collection.
It has an object in it holding parameters for searching. The user of the collection can call setSearchParam, and I have a method buildSearchString that will build the search part of the URL to call (I use the Matrix parameters in my REST urls).
window.SearchCollection = Backbone.Collection.extend({
initialize : function() {
this.params = {}; // holds parameters for searching
},
// Set a search param
setSearchParam: function(param, value) {
if (typeof value === 'undefined') return;
if (typeof this.params === 'undefined') this.params = {};
this.params[param] = value;
},
setSearchParams : function(paramMap) {
_.extend(this.params, paramMap);
},
// Build Matrix params for search. This could just as easily be a standard URL string
buildSearchString: function() {
var search = [];
var i = 0;
for (var key in this.params) {
var value = this.params[key];
if (utils.isEmpty(value)) continue;
search[i++] = ";";
search[i++] = key;
search[i++] = "=";
search[i++] = value;
}
return search.join('');
}
});
Then when I create a collection, I extend it:
window.BookingCollection = window.SearchCollection.extend({
model: Booking,
url: function(){
var urlString = BASE_REST_URL + "bookings/";
// Build the matrix params for the REST URL
urlString += this.buildSearchString();
return urlString;
}
});
Then, a user of this collection can use it like so:
var bookings = new BookingCollection();
bookings.setSearchParam("name", "hello");

comments module in dotnetnuke

Is there any comments module in Dotnetnuke that can work with the journal module? I mean, if a user comments on a page, the journal module on his profile displays that this user has commented on this page? Or, could there be an item having a link to that page? Just like we have in facebook? I hope you understand my question.
There is no such module. You would have to write your own
This is some sample code from the upcoming Announcements module:
public static void AddAnnouncementToJournal(AnnouncementInfo announcement, int tabId)
{
JournalItem item2 = new JournalItem
{
PortalId = announcement.PortalID,
ProfileId = announcement.LastModifiedByUserID,
UserId = announcement.LastModifiedByUserID,
ContentItemId = announcement.ContentItemID,
Title = announcement.Title
};
ItemData data = new ItemData
{
Url = announcement.Permalink()
};
item2.ItemData = data;
item2.Summary = HtmlUtils.Shorten(HtmlUtils.Clean(System.Web.HttpUtility.HtmlDecode(announcement.Description), false), 250, "...");
item2.Body = null;
item2.JournalTypeId = 33;
item2.SecuritySet = "E,";
JournalItem journalItem = item2;
JournalController.Instance.SaveJournalItem(journalItem, tabId);
}
Important to note: you need to define your own JournalType (in the sample above, this is not fully implemented yet, and using a hard coded value of 33). Basically, what you need is a new record in the JournalTypes table, defining your own journalType

Resources