Skip to content
This repository has been archived by the owner on Sep 15, 2024. It is now read-only.

Commit

Permalink
Add facades for Material $mdToast and $mdDialog services.
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Mackler authored and Adam Mackler committed Feb 28, 2016
1 parent 6be73f5 commit 422765f
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package com.greencatsoft.angularjs.extensions.material

import com.greencatsoft.angularjs.{injectable, AngularElement}
import com.greencatsoft.angularjs.core.{Event, Promise, Scope}
import org.scalajs.dom.Element
import org.scalajs.dom.raw.ClientRect
import scalajs.js
import js.annotation.ScalaJSDefined

@js.native
@injectable("$mdDialog")
trait MdDialog extends js.Object {
/** Builds a preconfigured dialog with the specified message. */
def alert(): MdDialogPreset = js.native
/** Builds a preconfigured dialog with the specified message.
* You can call show and the promise returned will be resolved
* only if the user clicks the confirm action on the dialog. */
def confirm(): MdDialogPreset = js.native
/** Show a dialog with the specified options. */
def show[T](options: MdDialogOptions): Promise[T] = js.native
def show[T](preset: MdDialogPreset): Promise[T] = js.native
/** Hide an existing dialog and resolve the promise returned from
* `$mdDialog.show().` Returns a promise that is resolved when
* the dialog has been closed. */
def hide[T](response: T): Promise[T] = js.native
/** Hide an existing dialog and reject the
* promise returned from $mdDialog.show(). */
def cancel[T](response: T): Promise[T] = js.native
}

@ScalaJSDefined
trait MdDialogOptions extends js.Object {
/** The url of a template that will be used as the content of the dialog. */
val templateUrl: String
/** HTML template to show in the dialog. This must be trusted HTML with
* respect to Angular's $sce service. This template should never be
* constructed with any kind of user input or user data. */
val template: String
/** Whether or not to automatically wrap the template with a
* <md-dialog> tag if one is not provided. Defaults to true.
* Can be disabled if you provide a custom dialog directive. */
val autoWrap: Boolean
/** A click's event object. When passed in as an option, the
* location of the click will be used as the starting point for
* the opening animation of the the dialog. */
val targetEvent: DOMClickEvent
/** The query selector, DOM element or the Rect object that is
* used to determine the bounds (top, left, height, width) from
* which the Dialog will originate. */
val openFrom: Element
/** The query selector, DOM element or the Rect object that is
* used to determine the bounds (top, left, height, width) to
* which the Dialog will target. */
val closeTo: Element
/** the scope to link the template / controller to. If none is
* specified, it will create a new isolate scope. This scope will
* be destroyed when the dialog is removed unless `preserveScope` is
* set to true. */
val scope: js.UndefOr[js.Object]
/** whether to preserve the scope when the element is removed.
* Default is false */
val preserveScope: js.UndefOr[Boolean]
/** Whether to disable scrolling while the dialog is open. Default true. */
val disableParentScroll: js.UndefOr[Boolean]
/** Whether there should be an opaque backdrop behind the dialog. Default true. */
val hasBackdrop: js.UndefOr[Boolean]
/** Whether the user can click outside the dialog to close it. Default false. */
val clickOutsideToClose: js.UndefOr[Boolean]
/** Whether the user can press escape to close the dialog. Default true. */
val escapeToClose: js.UndefOr[Boolean]
/** An option to override focus behavior on open. Only disable if
* focusing some other way, as focus management is required for
* dialogs to be accessible. Defaults to true. */
val focusOnOpen: js.UndefOr[Boolean]
/** The controller to associate with the dialog. The controller will
* be injected with the local `$mdDialog`, which passes along a
* scope for the dialog. */
val controller: String
/** An object containing key/value pairs. The keys will be used as
* names of values to inject into the controller. For example,
* `locals: {three: 3}` would inject three into the controller, with
* the value 3. If `bindToController` is true, they will be
* copied to the controller instead. */
val locals: js.UndefOr[js.Object]
/** bind the locals to the controller, instead of passing them in.
* These values will not be available until after initialization. */
val bindToController: js.UndefOr[Boolean]
/** Similar to locals, except it takes promises as values, and the
* dialog will not open until all of the promises resolve. */
val resolve: js.UndefOr[js.Dictionary[Promise[_]]]
/** An alias to assign the controller to on the scope. */
val controllerAs: js.UndefOr[String]
/** The element to append the dialog to. Defaults to
* appending to the root element of the application. */
val parent: js.UndefOr[AngularElement]
/** Callback function used to announce the show() action is starting. */
val onShowing: js.UndefOr[js.Function]
/** Callback function used to announce when the show() action is finished. */
val onComplete: js.UndefOr[js.Function]
/** Callback function used to announce the close/hide() action is
* starting. This allows developers to run custom animations in
* parallel the close animations. */
val onRemoving: js.UndefOr[js.Function]
/** An option to apply `.md-dialog-fullscreen` class on open. */
val fullscreen: js.UndefOr[Boolean]
}

/** Returned from `alert()`, and `confirm()` with chainable configuration methods. */
@js.native
trait MdDialogPreset extends js.Object {
/** Sets the confirm title. */
def title(string: String): MdDialogPreset = js.native
/** Sets the confirm message. */
def textContent(string: String): MdDialogPreset = js.native
/** Sets the confirm message as HTML. Requires ngSanitize module to be loaded.
* HTML is not run through Angular's compiler. */
def htmlContent(string: String): MdDialogPreset = js.native
/** Sets the confirm "Okay" button text. */
def ok(string: String): MdDialogPreset = js.native
/** Sets the confirm "Cancel" button text. */
def cancel(string: String): MdDialogPreset = js.native
/** Sets the theme of the confirm dialog. */
def theme(string: String): MdDialogPreset = js.native
/** A click's event object. When passed in as an option, the
* location of the click will be used as the starting point for the
* opening animation of the the dialog. */
def targetEvent(event: DOMClickEvent): MdDialogPreset = js.native
}

@js.native
trait DOMClickEvent extends Event {
val target: js.UndefOr[ClientRect] = js.native
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.greencatsoft.angularjs.extensions.material

import scalajs.js
import com.greencatsoft.angularjs.injectable
import com.greencatsoft.angularjs.core.Promise

@js.native
@injectable("$mdToast")
trait MdToast extends js.Object {
/** Shows the toast.
* @param preset An `MdToastPreset` returned from {@link #simple()} and {@link build()}, */
def show(preset: MdToastPreset): Promise[Unit] = js.native
/** Shows the toast. */
def show(options: MdToastOptions): Promise[Unit] = js.native
/** Builds a preconfigured toast. */
def simple(): MdToastPreset = js.native
/** Creates a custom `MdToastPreset` that you can configure.
* @return a `MdToastPreset` with the chainable configuration methods for shows' options. */
def build(): MdToastPreset = js.native
}

@js.native
trait MdToastOptions extends js.Object {
/** The controller to associate with this toast. The controller will be injected the
* local $mdToast.hide( ), which is a function used to hide the toast. */
val controller: js.UndefOr[String] = js.native
/** The url of an html template file that will be used as the content of the
* toast. Restrictions: the template must have an outer `md-toast` element. */
val templateUrl: js.UndefOr[String] = js.native
/** How many milliseconds the toast should stay active before automatically closing.
* Set to 0 or false to have the toast stay open until closed manually. Default: 3000. */
val hideDelay: js.UndefOr[Int] = js.native
/** Where to place the toast. Available: any combination of 'bottom', 'left',
* 'top', 'right'. Default: 'bottom left'. */
val position: js.UndefOr[String] = js.native
}
object MdToastOptions {
val undefined = ().asInstanceOf[js.UndefOr[Nothing]]

def apply(controller: js.UndefOr[String] = undefined,
templateUrl: js.UndefOr[String] = undefined,
template: js.UndefOr[String] = undefined,
hideDelay: js.UndefOr[Int] = undefined,
position: js.UndefOr[String] = undefined): MdToastOptions =
js.Dynamic.literal(
"controller" -> controller,
"templateUrl" -> templateUrl,
"template" -> template,
"hideDelay" -> hideDelay,
"position" -> position
).asInstanceOf[MdToastOptions]
}

@js.native
trait MdToastPreset extends js.Object {

/** Sets the toast content to the specified string. */
def textContent(c: String): MdToastPreset = js.native
/** Adds an action button. If clicked, the promise (returned from `show()`) will resolve with the
* value `'ok'`; otherwise, it is resolved with `true` after a `hideDelay` timeout. */
def action(a: String): MdToastPreset = js.native
/** Whether or not the action button will have an additional highlight class. **/
def highlightAction(h: Boolean): MdToastPreset = js.native
/** Whether or not to add the `md-capsule` class to the toast to provide rounded corners. */
def capsule(h: Boolean): MdToastPreset = js.native
/** Sets the theme on the toast to the requested theme. Default is `$mdThemingProvider`'s default. */
def theme(h: Boolean): MdToastPreset = js.native

}

0 comments on commit 422765f

Please sign in to comment.