commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / bower_components / angular-jquery-dialog-service / README.md
1 angular-jquery-dialog-service
2 =============================
3
4 # Overview
5 This service allows you to easily work with jQuery UI dialogs from Angular.js. A working sample can be viewed on [Plunker][2].
6
7 # Methods
8 The service exposes three methods for controlling the dialogs. These methods are `open()`, `close()`, and `cancel()`.
9
10 ## open(id, template, model, options)
11 The open method displays a dialog. The `id` argument is a unique name to identify this dialog when calling other methods on the service such as close and cancel.
12
13
14 The `template` argument specifies the id of the script block that contains the template to use for the dialog or a url to a template fragment on the web server. Here is an example script block template:
15
16 ```
17 <script type="text/ng-template" id="dialogTemplate.html">
18
19 <!-- Controller for Dialog -->
20 <div ng-controller="dialogCtrl">
21
22 <!-- The form -->
23 First Name<br>
24 <input type="text" ng-model="model.firstName" /><br>
25 Last Name<br>
26 <input type="text" ng-model="model.lastName" /><br>
27
28 <!-- The buttons -->
29 <button ng-click="cancelClick()">Cancel</button>
30 <button ng-click="saveClick()">Save</button>
31 <button ng-click="confirmClick()">Confirm</button>
32 </div>
33 </script>
34 ```
35
36 In the case above, `template` would be set to "dialogTemplate.html".
37
38 The `model` argument contains the data that should be passed to the dialog controller's scope. It is actually injected into the dialog controller's parent scope, but it is available as `$scope.model` within the dialog.
39
40 Finally, the `options` argument contains all of the [jQuery UI dialog options][1] that you would normally pass in the call to `dialog(options)`.
41
42 The open method returns a promise that is resolved when the user closes the dialog. If the dialog controller calls dialogService.close(model), the resolve function will be called. If `cancel()` is called or the user closed the dialog using the X or ESC, the reject function will be called.
43
44 Here is an example of an open call that opens a dialog whose template is in a script block assigned an id of "dialogTemplate.html":
45
46 ```javascript
47 dialogService.open("myDialog","dialogTemplate.html",
48 model: {
49 firstName: "Jason",
50 lastName: "Stadler",
51 update: false
52 },
53 options: {
54 autoOpen: false,
55 modal: true
56 }
57 }).then(
58 function(result) {
59 console.log("Closed");
60 console.log(result);
61 },
62 function(error) {
63 console.log("Cancelled");
64 }
65 );
66 ```
67
68 ## close(id, model)
69
70 This method is typically called by the dialog controller to close the dialog. The `id` argument is the same string passed to the open method. The `model` is the data the dialog should pass back in the promise to the caller.
71
72 ## cancel(id)
73
74 This method is typically called by the dialog controller to cancel the dialog. The `id` argument is the same string passed to the open method.
75
76
77 [1]: http://api.jquery.ui/dialog "JQuery UI Dialog Documentation"
78 [2]: http://plnkr.co/edit/ADYEsplnYr8NHqASCDgS "Plunker sample"
79