diff options
| author | Igor Minar | 2010-10-22 22:13:14 -0700 | 
|---|---|---|
| committer | Misko Hevery | 2010-10-23 14:38:08 -0700 | 
| commit | 5b40e87ac687fc52ba86f39daf62975b169acf41 (patch) | |
| tree | 4629c51f5e86d46a7c1792ede0257b6cc774aac0 /example/personalLog/personalLog.js | |
| parent | 1391f19fb49275af59230afef51b472c58d7818c (diff) | |
| download | angular.js-5b40e87ac687fc52ba86f39daf62975b169acf41.tar.bz2 | |
personalLog demo - initial version with spec
Diffstat (limited to 'example/personalLog/personalLog.js')
| -rw-r--r-- | example/personalLog/personalLog.js | 60 | 
1 files changed, 60 insertions, 0 deletions
| diff --git a/example/personalLog/personalLog.js b/example/personalLog/personalLog.js new file mode 100644 index 00000000..dbd0956f --- /dev/null +++ b/example/personalLog/personalLog.js @@ -0,0 +1,60 @@ +//app namespace +var example = {}; +example.personalLog = {}; + + +//name space isolating closure +(function() { + +var LOGS = 'logs'; + +/** + * The controller for the personal log app. + */ +function LogCtrl($cookieStore) { +  var self = this, +      logs = self.logs = $cookieStore.get(LOGS) || []; + + +  /** +   * Adds newMsg to the logs array as a log, persists it and clears newMsg. +   */ +  this.addLog = function(msg) { +    var newMsg = msg || self.newMsg; +    if (!newMsg) return; +    var log = { +      at: new Date().getTime(), +      msg: newMsg +    } + +    logs.push(log); +    $cookieStore.put(LOGS, logs); +    self.newMsg = ''; +  } + + +  /** +   * Persistently removes a log from logs. +   * @param {number} msgIdx Index of the log to remove. +   */ +  this.rmLog = function(msgIdx) { +    logs.splice(msgIdx,1); +    $cookieStore.put(LOGS, logs); +  } + + +  /** +   * Persistently removes all logs. +   */ +  this.rmLogs = function() { +    logs.splice(0); +    $cookieStore.remove(LOGS); +  } +} + +//inject +LogCtrl.$inject = ['$cookieStore']; + +//export +example.personalLog.LogCtrl = LogCtrl; +})();
\ No newline at end of file | 
