root/coldbox/trunk/src/system/plugins/messagebox.cfc @ 634

Revision 634, 6.2 kB (checked in by lmajano, 6 years ago)

code cleanup

Line 
1<!-----------------------------------------------------------------------
2********************************************************************************
3Copyright 2005-2007 ColdBox Framework by Luis Majano and Ortus Solutions, Corp
4www.coldboxframework.com | www.luismajano.com | www.ortussolutions.com
5********************************************************************************
6
7Author   :      Luis Majano
8Date     :      September 23, 2005
9Description :
10        This plugin is used by the framework for displaying alert message boxes.
11        The user has three types of messages: 1) Warning 2) Error 3) Information
12        The message is stored in the session scope. It can be changed to client
13        by changing the framework's settings.xml file.
14        The look can be altered by creating a class and setting it in the config.xml.cfm
15
16Modification History:
1706/09/2006 - Updated for coldbox.
1807/29/2006 - Flag to leave contents in the messagebox or delete them once rendered.
1910/10/2006 - Added the renderit method for usage under Blue Dragon, removed the render.
2001/28/2007 - Prepared for 1.2.0, using new storage centers.
21----------------------------------------------------------------------->
22<cfcomponent name="messagebox"
23                         hint="This is the messagebox plugin. It uses the session/client scope to save messages."
24                         extends="coldbox.system.plugin"
25                         output="false"
26                         cache="true">
27
28<!------------------------------------------- CONSTRUCTOR ------------------------------------------->
29
30        <cffunction name="init" access="public" returntype="messagebox" output="false">
31                <cfargument name="controller" type="any" required="true">
32                <cfset super.Init(arguments.controller) />
33                <cfset setpluginName("Messagebox")>
34                <cfset setpluginVersion("1.1")>
35                <cfset setpluginDescription("This is a visual plugin that creates message boxes.")>
36                <cfset instance.storageScope = getController().getSetting("MessageBoxStorage",true)>
37                <cfreturn this>
38        </cffunction>
39
40<!------------------------------------------- PUBLIC ------------------------------------------->
41
42        <!--- Storage Scope --->
43        <cffunction name="getstorageScope" access="public" output="false" returntype="string" hint="Get storageScope">
44                <cfreturn instance.storageScope/>
45        </cffunction>
46        <cffunction name="setstorageScope" access="public" output="false" returntype="void" hint="Set storageScope. If not session/client, then it defaults to the framework setting.">
47                <cfargument name="storageScope" type="string" required="true"/>
48                <!--- Validate Scope --->
49                <cfif reFindnocase("(session|client)",arguments.storageScope)>
50                        <cfset instance.storageScope = arguments.storageScope/>
51                <cfelse>
52                        <cfset instance.storageScope = getController().getSetting("MessageBoxStorage",true)>
53                </cfif>
54        </cffunction>
55
56        <!--- ************************************************************* --->
57
58        <cffunction name="setMessage" access="public" hint="Create a new messagebox. Look at types." output="false" returntype="void">
59                <!--- ************************************************************* --->
60                <cfargument name="type"     required="true" type="string" hint="The message type.Available types [error][warning][info]">
61                <cfargument name="message"  required="true" type="string" hint="The message to show.">
62                <!--- ************************************************************* --->
63                <cfset var msgStruct = structnew()>
64                <cfif refindnocase("(error|warning|info)", trim(arguments.type))>
65                        <cfset msgStruct.type = arguments.type>
66                        <cfset msgStruct.message = arguments.message>
67                        <cfwddx action="cfml2wddx" input="#msgStruct#" output="#getstorageScope()#.ColdBox_fw_messagebox">
68                <cfelse>
69                        <cfthrow type="Framework.plugins.messagebox.InvalidMessageTypeException" message="The message type sent in: #arguments.type# is invalid. Available types: error,warning,info">
70                </cfif>
71        </cffunction>
72
73        <!--- ************************************************************* --->
74
75        <cffunction name="getMessage" access="public" hint="Returns a structure of the message if it exists, else a blank structure." returntype="any" output="false">
76                <cfset var rtnStruct = structnew()>
77                <cfset var Storage = getstorageScope() & ".ColdBox_fw_messagebox">
78                <cfif structKeyExists(evaluate(getstorageScope()),"ColdBox_fw_messagebox")>
79                        <cfwddx action="wddx2cfml" input="#evaluate(storage)#" output="rtnStruct">
80                <cfelse>
81                        <cfset rtnStruct.type = "">
82                        <cfset rtnStruct.message = "">
83                </cfif>
84                <cfreturn rtnStruct>
85        </cffunction>
86
87        <!--- ************************************************************* --->
88
89        <cffunction name="clearMessage" access="public" hint="Clears the message structure by deleting it from the session scope." output="false" returntype="void">
90                <cfset var Storage = evaluate(getstorageScope())>
91                <cfif structKeyExists(Storage,"ColdBox_fw_messagebox")>
92                        <cfset structdelete(Storage, "ColdBox_fw_messagebox")>
93                </cfif>
94        </cffunction>
95
96        <!--- ************************************************************* --->
97
98        <cffunction name="isEmpty" access="public" hint="Checks wether the messagebox is empty or not." returntype="boolean" output="false">
99                <cfset var Storage = evaluate(getstorageScope())>
100                <cfif structKeyExists(Storage,"ColdBox_fw_messagebox")>
101                        <cfif structisEmpty(getMessage())>
102                                <cfreturn true>
103                        <cfelse>
104                                <cfreturn false>
105                        </cfif>
106                <cfelse>
107                        <cfreturn true>
108                </cfif>
109        </cffunction>
110
111        <!--- ************************************************************* --->
112
113        <cffunction name="renderit" access="public" hint="Renders the message box and clears the message structure by default." output="false" returntype="any">
114                <!--- ************************************************************* --->
115                <cfargument name="clearFlag" type="boolean" required="false" default="true" hint="Flag to clear the message structure or not after rendering. Default is true.">
116                <cfset var msgStruct = getMessage()>
117                <cfset var results = "">
118                <cfif msgStruct.type neq "">
119                        <cfsavecontent variable="results"><cfinclude template="../includes/messagebox.cfm"></cfsavecontent>
120                <cfelse>
121                        <cfset results = "">
122                </cfif>
123                <!--- Test to clear message structure --->
124                <cfif arguments.clearFlag>
125                        <cfset clearMessage()>
126                </cfif>
127                <cfreturn results>
128        </cffunction>
129
130        <!--- ************************************************************* --->
131
132</cfcomponent>
Note: See TracBrowser for help on using the browser.