Created
July 22, 2012 12:39
-
-
Save akshar100/3159539 to your computer and use it in GitHub Desktop.
PostModel
This file contains 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
var PostModel = Y.Base.create('postModel', Y.Model, [], { | |
sync: modelSync, | |
idAttribute: '_id', | |
profilePic: function () { | |
return baseURL + 'in/profile_pic/' + this.get('author_id'); | |
}, | |
initializer: function (config) { | |
}, | |
validate: function (attributes) { | |
attributes.text = Y.Lang.trim(attributes.text); | |
attributes.tags = Y.Lang.trim(attributes.tags); | |
if (!attributes.text || !Y.Lang.trim(attributes.text) || !Y.Lang.isString(attributes.text)) { | |
return "Text cannot be empty"; | |
} | |
if (!attributes.tags || !Y.Lang.trim(attributes.tags) || !Y.Lang.isString(attributes.tags)) { | |
return "Please provide brand,product,service names separated by comma"; | |
} | |
var tags = attributes.tags.split(","); | |
if (tags.length > 4) { | |
return "Provide only 4 brand,product,service names"; | |
} | |
if (!attributes.sector) { | |
return "You need to enter a valid sector."; | |
} else { | |
if (cache.retrieve("all_sectors")) { | |
if (!Y.Array.indexOf(cache.retrieve("all_sectors"), attributes.sector)) { | |
return "Please select a valid sector. The one you have provided is incorrect."; | |
} | |
} | |
} | |
} | |
}, { | |
ATTRS: { | |
id: { | |
value: null | |
}, | |
images: { | |
value: {} | |
}, | |
type: { | |
value: 'post' | |
}, | |
visible: { | |
value: true | |
}, | |
tags: { | |
value: 'forbash,sample' | |
}, | |
text: { | |
value: 'Default text' | |
}, | |
category: { | |
value: 'painpoint' | |
}, | |
author_id: { | |
value: 1 | |
}, | |
author: { | |
value: 'unknown' | |
}, | |
like: { | |
value: false | |
}, | |
dislike: { | |
value: false //DOES THE CURRENT USER LIKE THIS POST ? | |
}, | |
likes: { | |
value: 0 //TOTAL LIKES FOR THIS POST | |
}, | |
dislikes: { | |
value: 0 | |
}, | |
comments: { | |
value: 0 | |
}, | |
_id: { | |
value: 0 | |
}, | |
sector: { | |
value: '' | |
}, | |
sentiment:{ | |
value:'' | |
}, | |
ownership:{ | |
value:'public' | |
}, | |
comment_count:{ | |
value: 0 | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment