Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resolve option for custom modal #138

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Usage

```dialogs.notify('Something Happened','Something happened at this point in the application that I wish to let you know about');```

```dialogs.create('url/to/a/template','ctrlrToUse',{data: topass,anotherVar: 'value'},{});```
```dialogs.create('url/to/a/template','ctrlrToUse',{data: topass,anotherVar: 'value'},{resolve :{paramToResolve : function (){return 'value'}}});```

TODO: Add more usage explanations.

Demos
-----
- v4.2 : [Codepen: http://codepen.io/m-e-conroy/pen/rkIqv](http://codepen.io/m-e-conroy/pen/rkIqv)
- v4.2 : [Codepen: with UI-Bootstrap Date Picker directive](http://codepen.io/m-e-conroy/pen/DAxzs)
- v4.2 : [Codepen: with UI-Bootstrap Date Picker directive](http://codepen.io/m-e-conroy/pen/DAxzs)
- v2.0 : [Codepen: http://codepen.io/m-e-conroy/pen/AmBpL](http://codepen.io/m-e-conroy/pen/AmBpL)
- v1.0 : [Codepen: http://codepen.io/m-e-conroy/pen/ALsdF](http://codepen.io/m-e-conroy/pen/ALsdF)

Expand All @@ -42,7 +42,7 @@ Release Versions
- v3.0 : supports AngularJS 1.2 +, Angular UI Bootstrap 0.10.0
- v2.0 : supports AngularJS 1.2 +
- v1.0 : supports AngularJS 1.1.5 and below.


v5.2.8
------
Expand Down Expand Up @@ -124,7 +124,7 @@ v5.2.1 +
v5.2.x +
--------
1. [Angular Translate](https://github.com/angular-translate) is now optional.

v4.2.0 & v5.x.x
---------------
Same as v4.0.0 with the exception of the following:
Expand Down Expand Up @@ -155,7 +155,7 @@ v2.0 Additional Dependencies

v1.0
----
1. [Angular JS](http://www.angularjs.org) (version 1.1.5 and less)
1. [Angular JS](http://www.angularjs.org) (version 1.1.5 and less)
2. [Angular UI Bootstrap](http://angular-ui.github.io/bootstrap/#/modal) (version <= 0.6.0, Non-Bootstrap 3 Branch) with embedded templates.
3. [Twitter Bootstrap CSS](http://getbootstrap.com) (version 2)

Expand All @@ -175,10 +175,10 @@ Changes
- v5.2.x
1. Angular-Translate is now optional, however in order to keep support for Angular-Translate and be able to switch it on and off easily without having to add lines of code to your modules I created a substitute module that is automatically included and used when Angular-Translate is not found. This subsitute (*translate-substitution.js : translate.sub*) is a provider service (*$translateProvider*) with the same *translations* method as the Angular-Translate provider service does. The provider service is also named *$translate* and has its own *instant* method. I did this such that, if in the future you do decide to use Angular-Translate all you will have to do is load the module before the dialog's service is loaded.
2. The *dialogs-default-translations.js* file is also now an optional dependency.

- v5.1.0
1. Separated out the default translations into their own module: **dialogs-default-translations.js** Include this or the "min" version in your application if you are not already using $translationProvider elsewhere, otherwise just copy the translation list within the module to your translation list for 'en-US.'

- v5.0.0
1. Optionally pass in options object, possible overrides are as follows

Expand All @@ -203,7 +203,7 @@ Changes
- **dialogsProvider.useBackdrop([true,false,'static'])** - True or false to use a backdrop for the modal, 'static' to use a backdrop and disallow closing on mouse click of the backdrop.
- **dialogsProvider.useEscClose([true,false])** - Whether or not to allow the use of the 'ESC' key to close the modal
- **dialogsProvider.useClass([string])** - Sets an additional CSS class to the modal window
- **dialogsProvider.useCopy([true,false])** - Determines whether to use angular.copy or not when passing a data object to the custom dialog service. Setting this to false will allow the modal to retain the two-way binding with the calling controller - thus changing data in the modal will automatically change it in the calling controller's scope. The default is setting is true, so if you want the two-way binding you need to set this to false.
- **dialogsProvider.useCopy([true,false])** - Determines whether to use angular.copy or not when passing a data object to the custom dialog service. Setting this to false will allow the modal to retain the two-way binding with the calling controller - thus changing data in the modal will automatically change it in the calling controller's scope. The default is setting is true, so if you want the two-way binding you need to set this to false.
3. Main module is no longer *dialogs* as this would conflict with the new naming of the service. It is now *dialogs.main,* include that in your application's module definition to use the *dialogs* service.
4. Added i18n support via [Angular-Translate](https://github.com/angular-translate), use the *$translateProvider* to set language specific defaults. Default language is currently *en-US.* An example is provided in the example folder that will show you how to change the defaults from English to Spanish. Translations can be set on the following:
- DIALOGS_ERROR (modal header)
Expand Down
19 changes: 18 additions & 1 deletion dist/dialogs-default-translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
DIALOGS_NO: "取消"
});

$translateProvider.translations('es',{
$translateProvider.translations('es-ES',{
DIALOGS_ERROR: "Error",
DIALOGS_ERROR_MSG: "Se ha producido un error.",
DIALOGS_CLOSE: "Cerrar",
Expand All @@ -85,6 +85,23 @@
DIALOGS_YES: "Sí",
DIALOGS_NO: "No"
});

$translateProvider.translations("fr-FR", {
DIALOGS_ERROR: "Erreur",
DIALOGS_ERROR_MSG: "Une erreur inconnue s'est produite.",
DIALOGS_CLOSE: "Fermer",
DIALOGS_PLEASE_WAIT: "Patientez svp",
DIALOGS_PLEASE_WAIT_ELIPS: "Patienter svp...",
DIALOGS_PLEASE_WAIT_MSG: "En attente de la fin de l'opération.",
DIALOGS_PERCENT_COMPLETE: "% Terminer",
DIALOGS_NOTIFICATION: "Notification",
DIALOGS_NOTIFICATION_MSG: "Notification de l'application inconnue",
DIALOGS_CONFIRMATION: "Confirmer",
DIALOGS_CONFIRMATION_MSG: "Merci de confirmer",
DIALOGS_OK: "OK",
DIALOGS_YES: "Oui",
DIALOGS_NO: "Non"
});

$translateProvider.preferredLanguage('en-US');
}]); // end config
2 changes: 1 addition & 1 deletion dist/dialogs-default-translations.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 19 additions & 18 deletions dist/dialogs.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])

/**
* Use Backdrop
*
*
* Sets the use of the modal backdrop. Either to have one or not and
* whether or not it responds to mouse clicks ('static' sets the
* whether or not it responds to mouse clicks ('static' sets the
* backdrop to true and does not respond to mouse clicks).
*
* @param val mixed (true, false, 'static')
Expand All @@ -226,7 +226,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])

/**
* Use ESC Close
*
*
* Sets the use of the ESC (escape) key to close modal windows.
*
* @param val boolean
Expand All @@ -250,7 +250,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])

/**
* Use Copy
*
*
* Determines the use of angular.copy when sending data to the modal controller.
*
* @param val boolean
Expand All @@ -275,7 +275,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
/**
* Set Size
*
* Sets the modal size to use (sm,lg,md), requires Angular-ui-Bootstrap 0.11.0 and Bootstrap 3.1.0 +
* Sets the modal size to use (sm,lg,md), requires Angular-ui-Bootstrap 0.11.0 and Bootstrap 3.1.0 +
*
* @param val string (sm,lg,md)
*/
Expand Down Expand Up @@ -305,7 +305,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])


this.$get = ['$modal',function ($modal){

return {
/**
* Error Dialog
Expand Down Expand Up @@ -337,7 +337,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
}
}); // end modal.open
}, // end error

/**
* Wait Dialog
*
Expand Down Expand Up @@ -370,7 +370,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
}
}); // end modal.open
}, // end wait

/**
* Notify Dialog
*
Expand Down Expand Up @@ -401,7 +401,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
}
}); // end modal.open
}, // end notify

/**
* Confirm Dialog
*
Expand Down Expand Up @@ -432,7 +432,7 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
}
}); // end modal.open
}, // end confirm

/**
* Create Custom Dialog
*
Expand All @@ -443,7 +443,14 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
*/
create : function(url,ctrlr,data,opts){
var copy = (opts && angular.isDefined(opts.copy)) ? opts.copy : _copy;
var resolve = (opts && angular.isDefined(opts.resolve))? opts.resolve : {};
opts = _setOpts(opts);
resolve.data = function() {
if(copy)
return angular.copy(data);
else
return data;
};

return $modal.open({
templateUrl : url,
Expand All @@ -454,21 +461,15 @@ angular.module('dialogs.services',['ui.bootstrap.modal','dialogs.controllers'])
windowClass: opts.wc,
size: opts.ws,
animation: opts.anim,
resolve : {
data : function() {
if(copy)
return angular.copy(data);
else
return data;
}
}
resolve : resolve
}); // end modal.open
} // end create

}; // end return

}]; // end $get
}]); // end provider dialogs

//== Dialogs.Main Module =====================================================//

/**
Expand Down
Loading