Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Павел Резуненко
/
MTAweb
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
1
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit f3bb6197
authored
Mar 27, 2013
by
Павел Резуненко
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Удален
1 parent
85e631f2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
0 additions
and
819 deletions
public/app/controller/controller.js
public/app/controller/controller.js
deleted
100644 → 0
View file @
85e631f
Ext
.
define
(
'MyMA.controller.Users'
,
{
extend
:
'Ext.app.Controller'
,
stores
:
[
'Users'
,
'Choice'
],
views
:
[
'Users'
,
'User'
],
refs
:
[{
selector
:
'users > grid'
,
ref
:
'usersList'
},
{
selector
:
'users'
,
ref
:
'usersWindow'
}],
init
:
function
()
{
this
.
control
({
'users > grid > toolbar > #addrecord'
:
{
click
:
this
.
showForm
},
'users > grid > toolbar > #search'
:
{
click
:
this
.
onSearch
},
'users actioncolumn'
:
{
click
:
this
.
onActionColumn
}
});
},
/**
* Handles action columns click
* @param {Object} grid view
* @param {HTMLElement} Element
* @param {Integer} row index
* @param {Integer} column index
* @param {Object} Event object
* @param {Object} Scope object
* @param {Object}
*/
onActionColumn
:
function
(
gridview
,
el
,
rowIndex
,
colIndex
,
e
,
scope
,
rowEl
)
{
if
(
e
.
getTarget
(
'.x-ibtn-edit'
))
{
var
record
=
scope
.
store
.
getAt
(
rowIndex
);
var
widget
=
this
.
getController
(
'Taskpanel'
).
addProgram
({
name
:
'user'
});
widget
.
setTitle
(
'User: '
+
record
.
get
(
'name'
));
widget
.
down
(
'form'
).
getForm
().
loadRecord
(
record
);
}
if
(
e
.
getTarget
(
'.x-ibtn-delete'
))
{
var
record
=
scope
.
store
.
getAt
(
rowIndex
);
Ext
.
Msg
.
confirm
(
'Info'
,
'Press Yes to conform remove action'
,
function
(
button
)
{
if
(
button
===
'yes'
)
{
this
.
record
.
destroy
({
scope
:
this
,
success
:
function
()
{
this
.
store
.
remove
(
this
.
record
)
}
});
}
},
{
store
:
scope
.
store
,
record
:
record
});
}
},
/**
* Show form to add new record or edit existing data
* @param {Object} Button
*/
showForm
:
function
(
Button
)
{
this
.
getController
(
'Taskpanel'
).
addProgram
({
name
:
'user'
,
title
:
'New User'
});
},
/**
* Search action
*/
onSearch
:
function
(
Button
)
{
this
.
getUsersList
().
getStore
().
reload
({
params
:
Button
.
up
(
'toolbar'
).
getValues
()
});
}
});
Ext
.
define
(
'MyMA.controller.ProgramMenu'
,
{
extend
:
'Ext.app.Controller'
,
init
:
function
()
{
this
.
control
({
'programmenu > menu'
:
{
click
:
this
.
LaunchProgram
}
});
},
LaunchProgram
:
function
(
menu
,
item
)
{
if
(
item
.
itemId
==
'logout'
)
{
this
.
getController
(
'Viewport'
).
Logout
();
}
else
{
this
.
getController
(
'Taskpanel'
).
addProgram
({
name
:
item
.
widgetName
,
title
:
item
.
text
});
}
}
});
Ext
.
define
(
'MyMA.controller.Program'
,
{
extend
:
'Ext.app.Controller'
,
stores
:
[
'Programs'
],
refs
:
[{
selector
:
'taskpanel'
,
ref
:
'taskPanel'
}],
init
:
function
()
{
var
control
=
{};
Ext
.
each
(
this
.
refs
,
function
(
item
){
this
.
control
[
item
.
selector
]
=
{
beforeclose
:
this
.
me
.
programStop
,
hide
:
this
.
me
.
programState
,
show
:
this
.
me
.
programState
,
minimize
:
this
.
me
.
programMinimize
}
},
{
control
:
control
,
me
:
this
});
this
.
control
(
control
);
},
/**
* Register controll for the created "Program"
* @param String, selector name
*/
registerControl
:
function
(
selector
)
{
var
selector
=
selector
||
null
,
ctrl
=
{};
if
(
!
selector
)
{
return
;
}
ctrl
[
selector
]
=
{
beforeclose
:
this
.
programStop
,
hide
:
this
.
programState
,
show
:
this
.
programState
,
minimize
:
this
.
programMinimize
};
this
.
control
(
ctrl
);
},
// end registerControl()
/**
* Hides widget and sets status to the Store object
* @param {Object} item
*/
programMinimize
:
function
(
item
)
{
var
record
;
if
(
!
(
record
=
this
.
getStore
(
'Programs'
).
getProccess
({
property
:
'item'
,
value
:
item
.
getId
()
})))
{
return
false
;
}
this
.
getTaskPanel
().
items
.
get
(
record
.
get
(
'control'
)).
toggle
(
false
);
item
.
hide
();
this
.
programState
(
item
);
},
// end programMinimize()
/**
* Writes program state to the Store object
* @param {Object} item
* @param {Object} opt
*/
programState
:
function
(
item
,
opt
)
{
var
record
;
if
(
!
(
record
=
this
.
getStore
(
'Programs'
).
getProccess
({
property
:
'item'
,
value
:
item
.
getId
()
})))
{
return
false
;
}
record
.
set
(
'state'
,
item
.
isHidden
()
?
'hide'
:
'show'
);
},
// end programState()
/**
* Destroyes wiget and removes program information from the Store
* @param {Object} item
* @param {Object} record
*/
programStop
:
function
(
item
,
record
)
{
var
record
=
record
||
Ext
.
undefined
;
if
(
!
record
[
'data'
])
{
(
record
=
this
.
getStore
(
'Programs'
).
getProccess
({
property
:
'item'
,
value
:
item
.
getId
()
}));
}
if
(
item
.
animateTarget
)
{
item
.
animateTarget
=
null
;
}
if
(
record
&&
record
[
'data'
])
{
this
.
getTaskPanel
().
items
.
get
(
record
.
get
(
'control'
)).
destroy
();
this
.
getStore
(
'Programs'
).
remove
(
record
);
}
}
// end programStop()
});
/**
* Controller: Viewport
*
*/
Ext
.
define
(
'MyMA.controller.Viewport'
,
{
extend
:
'Ext.app.Controller'
,
views
:
[
'Viewport'
,
'Authorize'
],
refs
:
[{
selector
:
'viewport'
,
ref
:
'appView'
},
{
selector
:
'authorize'
,
ref
:
'authPanel'
},
{
selector
:
'authorize > form'
,
ref
:
'authForm'
}],
/**
*
*/
isGuest
:
Ext
.
undefined
,
/**
* A template method that is called when your application boots.
* It is called before the Application's launch function is executed so gives a hook
* point to run any code before your Viewport is created.
*/
init
:
function
(
app
)
{
// Bind Guest to the Ext.data.Connection
Ext
.
override
(
Ext
.
data
.
Connection
,
{
/**
* Set guest state to the authorization controller
*/
setGuest
:
Ext
.
Function
.
bind
(
this
.
setGuest
,
this
),
/**
* Return isGuest current value
* @return {Boolean}
*/
getGuest
:
Ext
.
Function
.
bind
(
this
.
getGuest
,
this
)
});
this
.
control
({
'authorize > form > toolbar > button'
:
{
click
:
this
.
Authorize
}
});
this
.
Authorize
();
},
/**
* Authorize
* if passed main application view, the first step need to query
* @param object, main application view
*/
Authorize
:
function
()
{
if
(
this
.
getAuthPanel
())
{
var
form
=
this
.
getAuthPanel
().
down
(
'form'
).
getForm
();
if
(
form
.
isValid
())
{
form
.
submit
({
url
:
Ext
.
Ajax
.
getRestUrl
(
'api'
,
'login'
,
'authorize'
,
0
),
method
:
'PUT'
,
clientValidation
:
true
,
scope
:
this
,
success
:
this
.
successLogin
})
}
}
else
{
Ext
.
Ajax
.
request
({
url
:
Ext
.
Ajax
.
getRestUrl
(
'api'
,
'login'
),
scope
:
this
,
callback
:
function
(){
if
(
!
this
.
isGuest
&&
!
this
.
getAppView
())
{
this
.
setGuest
(
false
);
this
.
getView
(
'Viewport'
).
create
();
}
}
});
}
},
/**
* Return isGuest value
* @param state
*/
getGuest
:
function
()
{
return
this
.
isGuest
;
},
/**
* Set isGuest flag value
* @param object, this controller
* @param boolean, state to set
*/
setGuest
:
function
(
state
)
{
this
.
isGuest
=
Ext
.
isBoolean
(
state
)
?
state
:
true
;
if
(
this
.
isGuest
&&
!
this
.
getAuthPanel
())
{
this
.
getView
(
'Authorize'
).
create
();
}
},
/**
* private
*/
successLogin
:
function
(
form
,
action
)
{
this
.
getAuthPanel
().
close
();
if
(
!
this
.
getAppView
())
{
this
.
getView
(
'Viewport'
).
create
();
}
},
/**
* Logout
* public
*/
Logout
:
function
()
{
Ext
.
Ajax
.
request
({
url
:
Ext
.
Ajax
.
getRestUrl
(
'api'
,
'login'
,
'logout'
,
0
),
method
:
'PUT'
,
scope
:
this
,
callback
:
function
()
{
if
(
this
.
getAppView
())
{
this
.
getController
(
'Taskpanel'
).
closeAll
();
this
.
getAppView
().
destroy
();
}
this
.
setGuest
(
this
,
true
);
}
});
}
});
/**
* Conroller: Alias
*
*/
Ext
.
define
(
'MyMA.controller.Alias'
,
{
extend
:
'Ext.app.Controller'
,
views
:
[
'Alias'
],
refs
:
[{
selector
:
'alias'
,
ref
:
'aliasWindow'
}],
init
:
function
()
{
this
.
control
({
'alias > toolbar > #savedata'
:
{
click
:
this
.
saveData
}
});
},
saveData
:
function
(
Button
)
{
var
form
=
this
.
getAliasWindow
().
down
(
'form'
).
getForm
(),
id
=
form
.
getValues
().
id
||
null
;
if
(
!
form
.
isValid
())
{
return
false
;
}
form
.
submit
({
url
:
Ext
.
Ajax
.
getRestUrl
(
'api'
,
'alias'
,
id
),
clientValidation
:
true
,
method
:
id
>
0
?
'PUT'
:
'POST'
,
scope
:
{
controller
:
this
,
win
:
this
.
getAliasWindow
()
},
success
:
this
.
onSuccessSubmit
,
failure
:
this
.
onFailSubmit
});
},
/**
*
*/
onSuccessSubmit
:
function
(
form
,
action
)
{
this
.
win
.
close
();
this
.
controller
.
getController
(
'Aliases'
).
getStore
(
'Aliases'
).
reload
({
params
:
{
start
:
0
}
});
Ext
.
Msg
.
showInfo
({
msg
:
'Data saved'
})
},
/**
*
*/
onFailSubmit
:
function
(
form
,
action
)
{
try
{
var
data
=
Ext
.
decode
(
action
.
response
.
responseText
);
throw
(
data
);
}
catch
(
e
)
{
Ext
.
Msg
.
showError
({
msg
:
e
});
}
}
});
Ext
.
define
(
'MyMA.controller.User'
,
{
extend
:
'Ext.app.Controller'
,
views
:
[
'User'
],
refs
:
[{
selector
:
'user'
,
ref
:
'userWindow'
}],
init
:
function
()
{
this
.
control
({
'user > toolbar > #savedata'
:
{
click
:
this
.
saveData
}
});
},
saveData
:
function
(
Button
)
{
var
form
=
this
.
getUserWindow
().
down
(
'form'
).
getForm
(),
id
=
form
.
getValues
().
id
||
null
;
if
(
!
form
.
isValid
())
{
return
false
;
}
form
.
submit
({
url
:
Ext
.
Ajax
.
getRestUrl
(
'api'
,
'user'
,
id
),
clientValidation
:
true
,
method
:
id
>
0
?
'PUT'
:
'POST'
,
params
:
Ext
.
applyIf
(
Ext
.
copyTo
({},
form
.
getValues
(),
'smtp,imap,manager'
),
{
smtp
:
0
,
imap
:
0
,
manager
:
0
}),
scope
:
{
controller
:
this
,
win
:
this
.
getUserWindow
()
},
success
:
this
.
onSuccessSubmit
,
failure
:
this
.
onFailSubmit
});
},
/**
*
*/
onSuccessSubmit
:
function
(
form
,
action
)
{
this
.
win
.
close
();
this
.
controller
.
getController
(
'Users'
).
getStore
(
'Users'
).
reload
({
params
:
{
start
:
0
}
});
Ext
.
Msg
.
showInfo
({
msg
:
'Data saved'
})
},
/**
*
*/
onFailSubmit
:
function
(
form
,
action
)
{
try
{
var
data
=
Ext
.
decode
(
action
.
response
.
responseText
);
throw
(
data
);
}
catch
(
e
)
{
Ext
.
Msg
.
showError
({
msg
:
e
});
}
}
});
Ext
.
define
(
'MyMA.controller.Aliases'
,
{
extend
:
'Ext.app.Controller'
,
stores
:
[
'Aliases'
],
views
:
[
'Aliases'
,
'Alias'
],
refs
:
[{
selector
:
'aliases > grid'
,
ref
:
'aliasesList'
}],
init
:
function
()
{
this
.
control
({
'aliases > grid > toolbar > #addrecord'
:
{
click
:
this
.
showForm
},
'aliases > grid > toolbar > #search'
:
{
click
:
this
.
onSearch
},
'aliases actioncolumn'
:
{
click
:
this
.
onActionColumn
}
});
},
/**
* Handles action columns click
* @param {Object} grid view
* @param {HTMLElement} Element
* @param {Integer} row index
* @param {Integer} column index
* @param {Object} Event object
* @param {Object} Scope object
* @param {Object}
*/
onActionColumn
:
function
(
gridview
,
el
,
rowIndex
,
colIndex
,
e
,
scope
,
rowEl
)
{
if
(
e
.
getTarget
(
'.x-ibtn-edit'
))
{
var
record
=
scope
.
store
.
getAt
(
rowIndex
);
var
widget
=
this
.
getController
(
'Taskpanel'
).
addProgram
({
name
:
'alias'
});
widget
.
setTitle
(
'Alias: '
+
record
.
get
(
'alias'
));
widget
.
down
(
'form'
).
getForm
().
loadRecord
(
record
);
}
if
(
e
.
getTarget
(
'.x-ibtn-delete'
))
{
var
record
=
scope
.
store
.
getAt
(
rowIndex
);
Ext
.
Msg
.
confirm
(
'Info'
,
'Press Yes to confirm remove action'
,
function
(
button
)
{
if
(
button
===
'yes'
)
{
this
.
record
.
destroy
({
scope
:
this
,
success
:
function
()
{
this
.
store
.
remove
(
this
.
record
)
}
});
}
},
{
store
:
scope
.
store
,
record
:
record
});
}
},
/**
* Show form to add new record or edit existing data
* @param {Object} Button
*/
showForm
:
function
(
Button
)
{
this
.
getController
(
'Taskpanel'
).
addProgram
({
name
:
'alias'
,
title
:
'New Alias'
});
},
/**
* Search action
*/
onSearch
:
function
(
Button
)
{
this
.
getAliasesList
().
getStore
().
reload
({
params
:
Button
.
up
(
'toolbar'
).
getValues
()
});
}
});
Ext
.
define
(
'MyMA.controller.Transports'
,
{
extend
:
'Ext.app.Controller'
,
stores
:
[
'Transports'
],
views
:
[
'Transports'
],
refs
:
[{
selector
:
'transports > grid'
,
ref
:
'transportsList'
}],
init
:
function
()
{
this
.
control
({
'transports > grid > toolbar > #addrecord'
:
{
click
:
this
.
addRecord
},
'transports > grid > toolbar > #search'
:
{
click
:
this
.
onSearch
},
'transports actioncolumn'
:
{
click
:
this
.
onActionColumn
},
'transports > grid'
:
{
edit
:
this
.
onEditAction
}
});
},
/**
* Handles action columns click
* @param {Object} grid view
* @param {HTMLElement} Element
* @param {Integer} row index
* @param {Integer} column index
* @param {Object} Event object
* @param {Object} Scope object
* @param {Object}
*/
onActionColumn
:
function
(
gridview
,
el
,
rowIndex
,
colIndex
,
e
,
scope
,
rowEl
)
{
if
(
e
.
getTarget
(
'.x-ibtn-delete'
))
{
var
record
=
scope
.
store
.
getAt
(
rowIndex
);
Ext
.
Msg
.
confirm
(
'Info'
,
'Press Yes to confirm remove action'
,
function
(
button
)
{
if
(
button
===
'yes'
)
{
if
(
!
this
.
record
.
get
(
'id'
))
{
this
.
store
.
remove
(
this
.
record
);
}
else
{
this
.
record
.
destroy
({
scope
:
this
,
success
:
function
()
{
this
.
store
.
remove
(
this
.
record
)
}
});
}
}
},
{
store
:
scope
.
store
,
record
:
record
});
}
},
/**
* Add record to the store and start editing
*/
addRecord
:
function
(
Button
)
{
this
.
getTransportsList
().
getStore
().
insert
(
0
,
this
.
getTransportsList
().
getStore
().
model
.
create
({
id
:
0
,
domain
:
null
,
transport
:
'virtual'
}));
},
/**
* Search action
*/
onSearch
:
function
(
Button
)
{
this
.
getTransportsList
().
getStore
().
reload
({
params
:
Button
.
up
(
'toolbar'
).
getValues
()
});
},
/**
* Fires when edit complete and record was updated
* @param {object}, Ext.grid.plugin.Editing
* @param {object}, An edit event
*/
onEditAction
:
function
(
editor
,
e
)
{
e
.
record
.
save
({
scope
:
e
,
success
:
function
(
record
)
{
this
.
store
.
reload
();
}
});
}
});
Ext
.
define
(
'MyMA.controller.Taskpanel'
,
{
extend
:
'Ext.app.Controller'
,
stores
:
[
'Programs'
],
refs
:
[{
selector
:
'taskpanel'
,
ref
:
'taskPanel'
}],
init
:
function
()
{
this
.
control
({
'taskpanel > button'
:
{
toggle
:
this
.
programState
}
});
},
/**
* Add program to the task panel
* @param data
*/
addProgram
:
function
(
data
)
{
var
data
=
data
||
{
name
:
null
},
store
=
this
.
getStore
(
'Programs'
),
record
,
widget
;
if
(
!
(
record
=
store
.
getProccess
({
property
:
'name'
,
value
:
data
.
name
})))
{
try
{
var
widget
=
Ext
.
widget
(
data
.
name
),
progId
=
(
store
.
max
(
'id'
)
||
0
)
+
1
;
}
catch
(
e
)
{
return
false
;
}
var
Button
=
this
.
getTaskPanel
().
add
({
xtype
:
'button'
,
ui
:
'program-button'
,
height
:
28
,
text
:
data
.
title
||
widget
.
title
,
enableToggle
:
true
,
pressed
:
true
,
programId
:
progId
});
record
=
store
.
add
({
id
:
progId
,
title
:
data
.
title
||
widget
.
title
,
name
:
data
.
name
,
state
:
'show'
,
item
:
widget
.
getId
(),
control
:
Button
.
getId
()
})[
0
];
this
.
getController
(
'Program'
).
registerControl
(
data
.
name
);
widget
.
animateTarget
=
Button
.
getId
();
widget
.
setTitle
(
data
.
title
);
widget
.
show
();
}
else
{
this
.
getTaskPanel
().
items
.
get
(
record
.
get
(
'control'
)).
toggle
(
true
);
if
((
widget
=
Ext
.
getCmp
(
record
.
get
(
'item'
))))
{
widget
.
show
();
}
}
return
widget
?
widget
:
null
;
},
/**
* Get reference function
* @param {Object} Button
*/
callRef
:
function
(
selector
)
{
var
me
=
this
;
try
{
for
(
var
i
=
0
,
ln
=
this
.
refs
.
length
;
i
<
ln
;
i
++
)
{
if
(
this
.
refs
[
i
][
'selector'
]
==
selector
)
{
return
me
[
'get'
+
Ext
.
String
.
capitalize
(
this
.
refs
[
i
][
'ref'
])]();
}
}
}
catch
(
e
)
{
}
return
null
;
},
programState
:
function
(
Button
)
{
var
store
=
this
.
getStore
(
'Programs'
),
record
,
widget
;
if
(
!
(
record
=
store
.
getProccess
({
property
:
'id'
,
value
:
Button
.
programId
})))
{
return
false
;
}
if
((
widget
=
Ext
.
getCmp
(
record
.
get
(
'item'
))))
{
widget
[
record
.
get
(
'state'
)
==
'show'
?
'hide'
:
'show'
]();
}
},
/**
* Close all process those are registed in the Programs storage
*/
closeAll
:
function
()
{
this
.
getStore
(
'Programs'
).
each
(
function
(
record
){
if
((
widget
=
Ext
.
getCmp
(
record
.
get
(
'item'
))))
{
widget
.
hide
();
this
.
getTaskPanel
().
items
.
get
(
record
.
get
(
'control'
)).
destroy
();
}
},
this
);
}
});
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment